简体   繁体   English

如何在WordPress网站中的jQuery插件中删除冲突?

[英]How to remove Conflict in a jQuery plugin in a WordPress website?

I am working on a WordPress website. 我正在WordPress网站上工作。 I have few filters of jQuery in it and all are working fine (I initiate these plugins using): 我在其中没有几个jQuery过滤器,并且都工作正常(我使用这些插件来初始化):

jQuery(document).ready(function($){
  /*code here*/
});

I am also using a jQuery Plugin "filter.js" which is having conflicting issues. 我还使用了存在冲突问题的jQuery插件“ filter.js” Even when I do not initiate this plugin (only on linking the plugin file to my page) it shows jQuery conflict and I can see in console: 即使我不启动此插件(仅在将插件文件链接到我的页面时),它仍显示jQuery冲突,并且可以在控制台中看到:

Uncaught TypeError: Cannot read property 'fn' of undefined 

You can find plugin source here . 您可以在此处找到插件源。

Try wrapping your code like this: 尝试像这样包装代码:

(function($){

    $(document).ready(function(){
         //document ready code here
    });

})(jQuery);

Wrap your filter.js plugin with the same wrapper, ie: 用相同的包装器包装filter.js插件,即:

(function($){

    //filter.js code here

})(jQuery);

If that's not working - make sure jQuery is included on the page. 如果这不起作用-请确保页面上包含jQuery。

Are you using two different versions of JQuery in the same page? 您是否在同一页面中使用两个不同版本的JQuery?

If so then use 如果是这样,请使用

<script type="text/javascript">
jQuery.noConflict();
</script>

just after the declaring the jQuery and replace all subsequet $ with jQuery 在声明jQuery之后并用jQuery替换所有子字符串$

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM