Jquery Mobile中pageinit等函数执行两次的问题【终极解决】
2014-08-15 15:28
351 查看
当禁用了jqueryMobile的ajax后,初始化函数如pageinit和pageshow等函数,都会执行两次。document.ready函数也会执行两次。
当然我们可以用一个变量记录是否已经执行,如果已经执行就不再执行第二次,但终究这不是最终办法。
ps:jqM是强烈建议,把原来的ready函数换成pageinit函数。
解决避免执行两次的办法是:在body中加如data-role="page",标记当前文档是page对象。
jqm中一个document中有多个page对象。当然也可以将div标记为page对象。
以下是原文:
The docs say very prominently not to use "$(document).ready()" any more but to use "pageInit()" instead.
So I am trying to change to pageInit() and also change from "window.open" to "pageChange".
I understand that to do this all pages should have the same header that references all the sources needed by any of the pages.
And I understand the page specific code has to be in the <div data-role="page"> element.
当然我们可以用一个变量记录是否已经执行,如果已经执行就不再执行第二次,但终究这不是最终办法。
var loaded = false;//防止执行重复 $(document).ready(function () { if (!loaded) { //do something loaded = true; } }); $(document).live('pageshow', function () { if (!loaded) { //do something loaded = true; } })
ps:jqM是强烈建议,把原来的ready函数换成pageinit函数。
解决避免执行两次的办法是:在body中加如data-role="page",标记当前文档是page对象。
jqm中一个document中有多个page对象。当然也可以将div标记为page对象。
以下是原文:
The docs say very prominently not to use "$(document).ready()" any more but to use "pageInit()" instead.
So I am trying to change to pageInit() and also change from "window.open" to "pageChange".
I understand that to do this all pages should have the same header that references all the sources needed by any of the pages.
And I understand the page specific code has to be in the <div data-role="page"> element.
相关文章推荐
- Jquery Mobile中pageinit等函数执行两次的问题【终极解决】
- 关于Asp.net页面Page_Load被执行两次的问题
- 关于Asp.net页面Page_Load被执行两次的问题
- android开发问题(二)解决ScrollView加入后无法执行OnGestureListener的监听函数
- 解决html按钮切换绑定不同函数后点击时执行多次函数问题
- while执行两次的问题,已经解决
- 正试图在 os 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起。问题的解决方法!
- 解决Spring定时计划任务重复执行两次(实例被构造两次)问题的方法
- 关于Asp.net页面Page_Load被执行两次的问题分享
- android SAX解析xml解决执行两次引起的问题
- 解决iphone safari下后退按钮导致函数不执行的问题
- Vs2003 转VS 2005 后 Page_Load 执行两次的问题
- 关于php页面最大执行时间问题(set_time_limit函数在windows下不起作用的解决)
- PHP执行函数超时,执行数据库超时等问题解决方法(9元包邮)
- jquery mobile使用a标签跳转页面时页面未执行pageinit事件的问题
- ASP.NET Page_load执行两次的解决办法
- Page_Load执行两次的解决方法
- javascript中运用闭包和自执行函数解决大量的全局变量问题
- 解决Ajax在兼容模式下后台调用执行两次结果不变的问题(已解决)!
- loadrunner 将执行脚本 写到vuser_init函数中问题