简体   繁体   English

页面刷新/刷新在jQuery Mobile的每个页面上执行$(document).ready()

[英]Page Reload/Refresh executes $(document).ready() on every page in jQuery Mobile

My jQuery mobile applications consists of multiple pages. 我的jQuery移动应用程序包含多个页面。

Whenever I reload a page, no matter which page in the application, $(document).ready() function is executed. 每当我重新加载页面时,无论应用程序中的哪个页面,都会执行$(document).ready()函数。 I expect it only to execute for the main page of the application. 我希望它只对应用程序的主页执行。

What is going on? 到底是怎么回事? I would like it only to run on the main page only. 我只希望它只在主页上运行。

Please read 请阅读

Important: Use pageInit(), not $(document).ready() 重要提示:请使用pageInit(),而不要使用$(document).ready()

The first thing you learn in jQuery is to call code inside the $(document).ready() function so everything will execute as soon as the DOM is loaded. 在jQuery中学习的第一件事是调用$(document).ready()函数中的代码,以便一旦加载DOM,一切都将执行。 However, in jQuery Mobile, Ajax is used to load the contents of each page into the DOM as you navigate, and the DOM ready handler only executes for the first page. 但是,在jQuery Mobile中,Ajax用于在导航时将每个页面的内容加载到DOM中,而DOM ready处理程序仅对第一页执行。 To execute code whenever a new page is loaded and created, you can bind to the pageinit event. 要在每次加载和创建新页面时执行代码,可以绑定到pageinit事件。 This event is explained in detail at the bottom of this page. 此事件在本页底部详细说明。

Also for jQM page information please read 另请参阅jQM页面信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM