jQuery 1.9使用$.support替代$.browser的使用方法

來源:互聯網
上載者:User

標籤:

jQuery 從 1.9 版開始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support

jQuery 從 1.9 版開始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,將不再支援 IE 6/7/8。 以後,如果使用者需要支援 IE 6/7/8,只能使用 jQuery 1.9。 如果要全面支援 IE,並混合使用 jQuery 1.9 和 2.0,官方的解決方案是:

<!--[if lt IE 9]>    <script src=‘jquery-1.9.0.js‘></script><![endif]--><!--[if gte IE 9]>    <script src=‘jquery-2.0.0.js‘></script><![endif]-->

判斷瀏覽器類型:

$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());$.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());$.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());$.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());


等號後面的運算式返回的就是 true/false, 可以直接用來替換原來的 $.browser.msie 等。如需要檢查是否為 IE6時,可以這麼寫:

// Oldif ($.browser.msie && 7 > $.browser.version) {}// Newif (‘undefined‘ == typeof(document.body.style.maxHeight)) {} 

檢查是否為 IE 6-8:

if (!$.support.leadingWhitespace) {} 

 

jQuery 1.9使用$.support替代$.browser的使用方法

聯繫我們

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