首頁  >  文章  >  web前端  >  淺析jQuery Mobile的初始化事件_jquery

淺析jQuery Mobile的初始化事件_jquery

WBOY
WBOY原創
2016-05-16 15:27:411775瀏覽

jQuery Mobile 包含一個初始化事件,該事件甚至會先於 jQuery 的 document.ready 事件進行載入。 jQuery Mobile 實際上在文件物件本身上觸發其初始化事件,第一個觸發的事件是mobileinit。

當Jquery Mobile開始執行時,他就會在document物件上觸發mobileinit 事件,因為mobileinit事件是在載入後馬上觸發,所以你需要在Jquery Mobile載入之前綁定你的事件處理函數,所以我建議你如下安排你的js引用順序

<script src="Jquery.js"></script>
<script src="您自己的js文件"></script>
<script src="Jquery-mobile.js"></script>

要擴充 mobileinit 事件,您首先需要將它與一個自訂函數進行綁定。可使用 bind 方法擴充 mobileinit 事件,來覆寫預設配置(全域選項)。

$(document).bind("mobileinit", function(){
//覆盖的代码
});

 

在綁定事件的函數內部,你可以使用$.mobile物件的$.extend方法來配置預設參數值:

$(document).bind("mobileinit", function(){
 $.extend( $.mobile , {
 foo: bar
 });
});

或單獨設定它。

$(document).bind("mobileinit", function(){
 $.mobile.foo = bar;
});

 

$.mobile 物件是設定所有屬性的起始點

<script type="text/java script" src="/scripts/jquery-1.6.min.js"></script>
<script type="text/java script">
$(document).bind("mobileinit", function(){
$.mobile.defaultTransition = "slidedown";
$.mobile.ajaxLinksEnabled = false; // 禁用Ajax提交
$.mobile.ajaxFormsEnabled = false; // 禁用Ajax提交
$.mobile.ajaxEnabled = false; //禁用Ajax提交
});
</script>
<script type="text/java script" src="/scripts/mobile/jquery.mobile-1.0b1.min.js"></script>

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn