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

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

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

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

感谢帮助!

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

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

您的代码完全按原样为我工作。

在此处输入图像描述

请务必注意,这仅在您加载单独页面时才有效。 它不适用于内部链接页面,因为它实际上并没有加载页面。