准备好的事件在翻页时触发 [英] Does ready event fire when page-turn

查看:96
本文介绍了准备好的事件在翻页时触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一本书,并使用 jQuery 来更改页面等。

顶部有一个 $ (document).ready(function(),它在加载页面时做了不同的事情。



在GUI页面上,我得到了一个change页面按钮,当这个按钮被按下时,调用函数 turnPage(),这个方法包含一些代码pluss:
$ b $ mobile.changePage(#device+ window.device,{
transition:slide,
reverse:false,
pre $ b changeHash:true
));

我的问题是,当 turnPage()被调用,也是 $(document).ready(function()被调用?

,我对此很陌生) DOM准备事件是DOM完全加载时触发的事件,除了图像< img> )。



每次页面加载时,该事件都会触发一次。所以:


  • 如果th e turn page()函数进行重定向,答案为 c $ c> turn page()函数仅获取 ajax 请求的数据,答案是






重要更新
我在官方插件网站



重要提示:使用pageInit(),而不是$(document).ready() p $ p $在jQuery中学习的东西是调用$(document).ready()函数中的代码,以便在DOM加载后立即执行所有操作。但是,在jQuery Mobile中,Ajax用于在浏览时将每个页面的内容加载到DOM中,而DOM就绪处理程序仅对第一页执行。要在加载并创建新页面时执行代码,可以绑定到pageinit事件。

...

...


blockquote>

所以转页做了一个 ajax 请求,所以最后答案是



准备好的活动是什么:


虽然JavaScript在呈现页面时提供执行代码的加载事件,但直到完全接收到所有资产(如图像)后才会触发此事件。在大多数情况下,脚本可以在DOM层次结构完全构建后立即运行。传递给.ready()的处理程序保证在DOM准备就绪后执行,因此这通常是附加所有其他事件处理程序并运行其他jQuery代码的最佳位置。使用依赖CSS样式属性值的脚本时,引用外部字符很重要。



I am making a book, and use jQuery to change pages etc.
At the top I have an $(document).ready(function() that does different stuff when the page is loaded.

On the GUI page I got a "change page" button, and when this is pushed, the function turnPage() is called. This method contain some code pluss this:

$.mobile.changePage("#device"+window.device, {
    transition: "slide",
    reverse: false,
    changeHash: true
});

My question is, when turnPage() is called, is also $(document).ready(function() called?
(Yes, I am new to this)

解决方案

DOM ready event is an event that fires when the DOM is fully loaded except of images (<img>).

The event fires once for each page load. So:

  • If the turn page() function makes a redirect, the answer is Yes.
  • If the turn page() function only gets data with ajax request, the answer is No.

Important Update: I found this in the official plugin website :

Important: Use pageInit(), not $(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. 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.
...
...

So turn page does an ajax request, so the final answer is No.

What is the ready event:

While JavaScript provides the load event for executing code when a page is rendered, this event does not get triggered until all assets such as images have been completely received. In most cases, the script can be run as soon as the DOM hierarchy has been fully constructed. The handler passed to .ready() is guaranteed to be executed after the DOM is ready, so this is usually the best place to attach all other event handlers and run other jQuery code. When using scripts that rely on the value of CSS style properties, it's important to reference external.

这篇关于准备好的事件在翻页时触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆