jQuery noConflict语法建议

时间:2018-12-02 20:43:51

标签: javascript jquery

请让我知道如何为以下JavaScript编写Jquery noConflict?有人建议我这个语法吗?

function openSearch() {
      $("#myOverlay").fadeIn(); // "500" is not required. "400" is the default value
  }

  function closeSearch() {
      $("#myOverlay").fadeOut();  // "500" is not required. ""400 is the default value
  }

1 个答案:

答案 0 :(得分:0)

使用未命名的函数包装器将jQuery作为参数传递。

jQuery.noConflict();
(function($){

  $("#myOverlay").fadeIn(); // "500" is not required. "400" is the default 
  $("#myOverlay").fadeOut();  // "500" is not required. ""400 is the default 

})(jQuery)