错误? Jquery Mobile Event仅使用live()和pageshow事件触发一次

时间:2012-04-11 16:30:32

标签: jquery jquery-mobile cordova

尝试使用jquery mobile来触发事件(登录点击按钮),但它只能运行一次。

我在'pageshow'事件上触发它(因为整个jquery ajax页面加载的东西,文件就绪不适用)但是它再次只能在第一次加载时工作,我尝试了一个可以触发的警报。所以它必须是$('。check-login')中的.live()事件。我希望你们能对它有所了解。

Jquery代码:

      $('#home').live('pageshow', function(event){
                             alert('home');//fires okay

                             //fires once only
                             $('.check-login').live('click', function() {
                                        var email = $("#email").val();
                                        var password = $("#password").val();
                                        if(email !="" || password !=""){
                                        var datastring = "useremail=" + email + "&userpassword=" + password;                 
                                                              $.ajax({
                                                              type: "POST",
                                                              url: 'http://creativetree.co/creativetreeBeta/mobileImageUpload.php',
                                                              data: datastring,
                                                              success: function(data){
                                                              //success
                                                              $('.check-login').slideUp();
                                                              $('.upload-page').fadeIn();
                                                              $('#userlogin').slideUp();  
                                                              }
                                                              });

                                        }else{
                                        alert('Please fill in all fields');
                                        }
                             });
                             });

1 个答案:

答案 0 :(得分:0)

通过:JqueryMobile - Scripting pages

因为当您在同一个项目(内部)上关注jQuery Mobile站点上的链接时,该页面将加载AJAX并且仅替换正文。因此,如果要在页面加载后添加的任何dom元素上触发任何事件,则需要使用.live()函数而不是单击。当你遍历页面而不是重新加载页面时,它只是来自jQuery-Mobile本身的内部ajax调用。