淺析jQuery Mobile的初始化事件_jquery

來源:互聯網
上載者:User

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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.