欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery插件版本沖突的處理方法分析

 更新時間:2017年01月16日 11:23:03   作者:ISaiSai  
這篇文章主要介紹了jQuery插件版本沖突的處理方法,結合具體實例形式分析了jQuery基于noConflict方法解決版本沖突的處理技巧,需要的朋友可以參考下

本文實例分析了jQuery插件版本沖突的處理方法。分享給大家供大家參考,具體如下:

jQuery 的某個插件 當有多個版本同時可能會有沖突,導致代碼錯誤

參考typeahead的處理方法,可以在插件中增加noconflict 方法來解決這個問題(在進入版本的時候講老版本保存,退出的時候還原老版本)

demo如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <script src="jquery.js"></script>
</head>
<body>
<div class="container">
  你好
</div>
<script>
  (function ($) {
    $.fn.myshowHtml = function () {
      alert("我是老版本:" + this.html());
    }
  })(window.jQuery);
  (function ($) {
    var old = $.fn.myshowHtml;
    $.fn.myshowHtml = function () {
      alert("我是新版本:" + this.html());
    }
    $.fn.myshowHtml.noConflict = function () {
      $.fn.myshowHtml = old;
      return this;
    };
  })(window.jQuery);
  $(function () {
    $(".container").myshowHtml();
    $.fn.myshowHtml.noConflict();
    $(".container").myshowHtml();
  })
</script>
</body>
</html>

更多關于jQuery相關內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》、《jQuery切換特效與技巧總結》、《jQuery遍歷算法與技巧總結》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結

希望本文所述對大家jQuery程序設計有所幫助。

相關文章

最新評論