Jquery 移动页面未响应事件

Jquery mobile page not responding to events

我正在尝试 运行 聊天应用程序,但我设置的点击侦听器无法正常工作。用户单击按钮时没有任何反应。我的代码有问题吗?

这是jquery/javascript脚本

<script> 
    $(document).on("pageinit",function(event){
        setInterval(update, 10000);
        setInterval(getMessage, 20000);

        $( "#submit" ).bind( "click", function(event, ui) {
            //get message
            var msg_display = $("#msg").val();
            //get chat_id, if not set, display an alert of not able to send, please select chat member
            var chat_id = $("#chat_id").val();
            //get user_id
            var user = $("#user").val();
            if(chat_id != ""){
                //send message
              sendMessage(msg_display, chat_id, user);  
            }else{
                alert("Please select a user to chat with");
                $("#msg").val("");
            }
});

        $( "#m_on li" ).bind( "click", function() {
          var selected_member = $(this).html();
          window.location = 'chat.php?chat_mate=' + selected_member;
            //reload this page with the values of member to chat with
});



        function update() { 
     $.ajax({
         type: 'POST',
           url: "update.php",
           success: function(result){
               //all good.
           }
     })
 }
        function sendMessage(msg, msg_id, from){
           $.ajax({
         type: 'POST',
           url: "send_message.php",
           data: {msg:msg, msg_id:msg_id, from:from},
           success: function(result){
               if(result == "good"){
                   getMessage(msg_id);
               }else{
                   alert("Not able to send message " + result);
               }
           }
     })
        }

        function getMessage(msg_id){
           $.ajax({
         type: 'POST',
           url: "get_message.php",
           data: {msg_id:msg_id},
           dataType: "json",
           success: function(result){
               //all good.
               ///append to the chats.
               for(var i=0, i < result.length; i++){
                   $("#chats").append("<p>" + result[i]['message'] + "</p>" +
                                      "<p align=right>Sent by " + result[i]['sender'] + " at " + 
                                       result[i]['time'] + "</p>");
               }
               $("#msg").val("");
               $('#chats').animate({scrollTop:$('#chats').prop("scrollHeight")}, 500);
           }
     })
        }
});
</script>

我在 html 中的按钮是;

<div id="chats"></div>
   <textarea cols="40" rows="8" name="msg" id="msg" placeholder="Message here..."></textarea>
   <input type="button" data-inline="true" id="submit" value="Submit">

pageinit有什么关系吗?

您的 for 循环语法有问题 for(var i=0, i < result.length; i++)("var i=0" 之后的“,”应该是“;”)

也许您应该多尝试调试一下 ;)