$(document).ready未在JQuery Mobile中触发[重复]

时间:2022-12-05 17:15:55

Possible Duplicate:
jQuery mobile $(document).ready equivalent
Does ready event fire when page-turn

可能重复:jQuery mobile $(document).ready等效当翻页时,就绪事件是否会触发

I Have two pages - Page1.html And Page2.html.
I am calling Page2.html from Page1.html.
In that scenario, $(document).ready is not firing in Page2.html.

我有两页 - Page1.html和Page2.html。我从Page1.html调用Page2.html。在那种情况下,$(document).ready没有在Page2.html中触发。

Code I used to navigate is:

我以前导航的代码是:

<li><a href="Page2.html" data-prefetch="true" data-transition="flip">Page 2</a></li>

1 个解决方案

#1


1  

see this http://jquerymobile.com/test/docs/api/events.html

请参阅此http://jquerymobile.com/test/docs/api/events.html

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. 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. To execute code whenever a new page is loaded and created, you can bind to the pageinit event.

你在jQuery中学到的第一件事就是在$(document).ready()函数中调用代码,这样一旦加载DOM就会执行所有操作。但是,在jQuery Mobile中,Ajax用于在导航时将每个页面的内容加载到DOM中,而DOM ready处理程序仅对第一个页面执行。要在加载和创建新页面时执行代码,您可以绑定到pageinit事件。

#1


1  

see this http://jquerymobile.com/test/docs/api/events.html

请参阅此http://jquerymobile.com/test/docs/api/events.html

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. 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. To execute code whenever a new page is loaded and created, you can bind to the pageinit event.

你在jQuery中学到的第一件事就是在$(document).ready()函数中调用代码,这样一旦加载DOM就会执行所有操作。但是,在jQuery Mobile中,Ajax用于在导航时将每个页面的内容加载到DOM中,而DOM ready处理程序仅对第一个页面执行。要在加载和创建新页面时执行代码,您可以绑定到pageinit事件。