简体   繁体   English

如何绑定到jquery-mobile pagebeforeload事件?

[英]How to bind to jquery-mobile pagebeforeload event?

I'm getting desperate trying to get the jQuery mobile pagebeforeload event to fire. 我正拼命试图触发jQuery mobile pagebeforeload事件。 This just does nothing: 这只是什么都不做:

 $(document).on("pagebeforeload", function( e, data ) {
        console.log("hello");
    });

According to the JQM docs , the syntax is correct. 根据JQM文档 ,语法是正确的。 Still, nothing happens. 仍然没有任何反应。 Can anybody tell me why that is? 有人可以告诉我为什么吗?

Your code worked for me exactly as it is. 您的代码对我来说完全一样。

在此处输入图片说明

Be sure to note that this will only work if you are loading a separate page. 请确保注意,这仅在您加载单独的页面时有效。 It will not work for internally linked pages because it is not actually loading a page. 对于内部链接的页面,它将不起作用,因为它实际上并未加载页面。

Make sure you're including preventDefault(); 确保您包含了preventDefault(); Otherwise, it'll just merrily continue loading. 否则,它会很愉快地继续加载。

Docs: http://jquerymobile.com/demos/1.1.0/docs/api/events.html 文件: http //jquerymobile.com/demos/1.1.0/docs/api/events.html

$( document ).bind( "pagebeforeload", function( event, data ){

    // Let the framework know we're going to handle the load.

    event.preventDefault();

    // ... load the document then insert it into the DOM ...
    // at some point, either in this callback, or through
    // some other async means, call resolve, passing in
    // the following args, plus a jQuery collection object
    // containing the DOM element for the page.

    data.deferred.resolve( data.absUrl, data.options, page );

});

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

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