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

问题描述:

我迫不及待地试图让jquery mobile pagebeforeload 事件发生。这没有任何作用:

I'm getting desperate trying to get the jquery mobile pagebeforeload event to fire. This just does nothing:

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

根据 JQM docs ,语法正确。但是,没有任何反应。 Anybode可以告诉我为什么会这样吗?

According to the JQM docs, the syntax is correct. Still, nothing happens. Can anybode tell me why that is?

感谢您的帮助!

确保你包含 preventDefault(); 否则,它会快乐地继续加载。

Make sure you're including preventDefault(); Otherwise, it'll just merrily continue loading.

文档: 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 );

});