Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未使用jQuery mobile将内容动态加载到DIV_Javascript_Css_Jquery Mobile_Jquery - Fatal编程技术网

Javascript 未使用jQuery mobile将内容动态加载到DIV

Javascript 未使用jQuery mobile将内容动态加载到DIV,javascript,css,jquery-mobile,jquery,Javascript,Css,Jquery Mobile,Jquery,这并没有确切地说明问题所在,只是有一个想法。例如,当我单击第2页时,内容不会加载到div中,我必须刷新页面才能看到第2页的内容 注:相同的代码在其他页面中重复 代码: $(document).ready(function() { $('.content-primary').html("Content of page 1"); // This line just in this example //$(".content-primary").load("content-of-pag

这并没有确切地说明问题所在,只是有一个想法。例如,当我单击第2页时,内容不会加载到div中,我必须刷新页面才能看到第2页的内容

注:相同的代码在其他页面中重复

代码:

$(document).ready(function() {
    $('.content-primary').html("Content of page 1"); // This line just in this example
    //$(".content-primary").load("content-of-page.php"); // but I used this code on all my pages 
});

这是一个常见的jQuery移动问题

您不应该将DocumentReady与jQM一起使用,相反,jQM提供页面事件。您的问题是文档就绪,谁可以,并且通常在页面加载到DOM之前触发。这就是为什么刷新有帮助,此时页面已经加载

我给你举了一个有效的例子:

基本上,每个页面事件都将触发仅用于该页面的javascript代码。如果希望代码只执行一次,则应使用pageinit事件而不是pagebeforeshow,如下所示:

$(document).on('pageinit', '#foo', function(){       
    alert('This is foo');
});

$(document).on('pageinit', '#bar', function(){       
    alert('This is bar');
});

如果您想找到更多信息,请查看我的另一篇文章/答案:

您的意思是这样的哦,对不起,当我更新JSFIDLE时,我遇到了这个错误。
$(document).on('pageinit', '#foo', function(){       
    alert('This is foo');
});

$(document).on('pageinit', '#bar', function(){       
    alert('This is bar');
});