解决方案 »

  1.   

    这里假定msgList是你从服务端获取到的消息列表的json
    <!DOCTYPE html >
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <script>
      function showMsg(){
      var msgList = [
      {sender:'小红',receiver:'',msgTime:'2015.1.7',content:'巴拉巴拉魔仙'},
      {sender:'小绿',receiver:'',msgTime:'2015.1.8',content:'魔仙变身'}
      ];
      for(var i=0;i<msgList.length;i++){
    document.getElementById("textarea").value += msgList[i].sender + "(" + msgList[i].msgTime + ")\r\n" + msgList[i].content +"\r\n";
      }
      }
      
      </script>
     </head> <body>
        <textarea name="textarea" id="textarea" cols="50" rows="7"></textarea >
      <input type="button" value="显示消息" onclick="showMsg();"/>
     </body>
    </html>
      

  2.   

    那么我如何实现通过direct(交互方向  1为发送人到接收人  2为接收人到发送人)这个量来实现类似于聊天记录的界面呢?
      

  3.   

    要做在线聊天,百度查询:comet在线聊天
      

  4.   

    还想问一下,我怎么遍历一个既有正常值又有list的一个list呀?就像我的类是这样的:
    public class LogicMsgInav  //交互消息表(逻辑表)
    {   
        public String sender;//发送人
        public String receiver;//接收人
        public List<MsgInav>;//交互消息表
    }
    public class MsgInav  //交互消息表
    {   
        public int direct;  //消息方向(1为发送人到接收人  2为接收人到发送人)
        public String msgTime;  //消息时间
        public String content;  //内容
    }
    如何遍历List<LogicMsgInav>,得到一次交互时的所有的值呢?这样可以得到这个对话框吗?
      

  5.   


    如果你用的是mvc的话,mvc提供了json格式输出,controller中伪代码如下:var jsonObj = new
                {
                    rows = service.GetList(sql),
                    total = service.total,
                    totalWell = service.totalWell
                };            return Json(jsonObj, JsonRequestBehavior.AllowGet);通过ajax调用该controller就能转化为json