jquery版本更新後無live函數的處理.TypeError: $(...).live is not a function

來源:互聯網
上載者:User

標籤:

 

jquery live函數文法

jquery版本更新, 發現一個問題: jq內建的live沒有了.
控制台下會有如下的提示:
Firefox: TypeError: $(...).live is not a function

chrome: Uncaught TypeError: Object [object Object] has no method ‘live‘ 

 

網上的一個說法: 
jQuery 1.9 較之前的版本做了很大的調整,很多函數都不被支援。
例如 live(),die(),toggle(),sub(),$.browser 等等都已經被移除,完整的更新內容見 http://jquery.com/upgrade-guide/1.9/ (英文)。
 
在不改變你網站代碼的同時,要使用 1.9 之後的版本,你需要使用 jQuery Migrate(轉移、過度),詳見 http://blog.jquery.com/2013/01/31/jquery-migrate-1-1-0-released/ (英文)。
Migrate 應該只是暫時性的。為了和 jQuery 保持同步,建議你從現在開始根據 1.9 的改變重寫你網站的所有代碼。
所以之前你的代碼如果是
$("#ele").live("click", function() {
    //...
});
現在要寫成
$("#ele").on("click", function() {
    //...
});
動態產生的元素要使用 live,要寫成
$(document).on("click", "#ele", function() {
    //...
});

jquery版本更新後無live函數的處理.TypeError: $(...).live is not a function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.