在 jQuery Mobile 中,如何定位使用 loadPage 创建的元素?
我使用 $.mobile.loadPage()
将“页面”加载到 DOM 中。然后我想定位创建的元素,但我还没有弄清楚如何做到这一点。这就是我认为可行的方法:
var toc = $.mobile.loadPage('toc.html');
toc.trigger('customevent');
上面的代码不起作用,部分原因是 toc
是一个“延迟承诺对象”,而不是一个好的 jQuery DOM 引用。此外,它不起作用,因为第二行在 loadPage 完成之前被触发。有没有办法在 loadPage 之后触发回调?
谢谢!
I load a "page" into the DOM using $.mobile.loadPage()
. I then want to target the element created, but I haven't figured out how to do this. This is what I thought would work:
var toc = $.mobile.loadPage('toc.html');
toc.trigger('customevent');
The above does not work in part because toc
is a "deferred promise object" rather than a good ol' jQuery DOM reference. Additionally, it does not work because the second line is triggered before loadPage finishes. Is there a way to fire a callback after loadPage?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您知道正在加载的页面的 id,那么您可以使用
.live()
将 'pagecreate' 事件绑定到该对象,如下所示:这将在页面加载到 dom 后触发。
If you know the id of the page being loaded then you can bind the 'pagecreate' event to that object with
.live()
like so:This will fire after the page has been loaded into the dom.
我只是能够弄清楚这一点,即使你没有 id,这里是我如何对插入的元素执行操作(淡入)的示例......
I just was just able to figure this out, even if you don't have the id, here's an example of how i am performing an action (fadeIn) on the the inserted element....
您可以使用
pageshow
在页面加载时触发回调。请参阅 jQuery Mobile 事件 API 了解更多详细信息。一个例子是这样的:
You can use
pageshow
in order to fire a callback when the page is loaded. Please refer to the jQuery Mobile Events API for more detail.An example would be something like: