问题描述
我已经开发了一段时间的wordpress插件,而且我的所有插件似乎总是遇到以下问题Jquery冲突问题.
I have been developing wordpress plugins for a while now and i always seem to get the following issues with all my plugins Jquery conflicts issues.
我尝试了许多不同的方法来避免这些问题,但是我总是让用户与我联系,说他们从我的插件中安装了一个插件后,它就停止了另一个插件的工作.
I have tried so many different ways to avoid these but i always get users contacting me saying when they have installed one off my plugins it has stopped another plugin from working aahhhhh.
我真的很想对这个问题进行分类,因为我知道这对人们来说是多么令人沮丧.
I really want to get this sorted because i understand how frustrating this can be for people.
我总是设置并选择或包括wordpresses jquery,下面仅是一个不起作用的示例.
I always set and option or include wordpresses jquery, below is just an example not working code.
add_action( 'init', array( $this, 'include_jquery' ) );
function include_jquery(){
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"), false, '1.7.1');
wp_enqueue_script('jquery');
}
好了,所以在出现问题之后,我现在在插件管理中有了一个选择选项,可以切换是或否以包含jquery,我知道它是自动安装的,但是有些用户删除了它,这对某些人有效,但不是全部.
Ok so after issues with this i now have a select option in the plugin admin to toggle yes or no to include jquery or not i know it is automatically installed but some users remove this, this works for some people but not all.
如果您包括wordpress jquery,我知道您必须使用以下内容运行jquery.
if you include the wordpress jquery i know you have to run your jquery with the following.
jQuery(document).ready(function ($) {
jQuery代替美元符号$
jQuery instead of the dollar sign $
我了解并使用了jquery并没有冲突,并尝试并测试了一些(如果不是全部的话) http://api.jquery.com/jQuery.noConflict/
i understand and have used jquery no conflict and tried and tested some if not all off thesehttp://api.jquery.com/jQuery.noConflict/
$.noConflict();
jQuery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
});
与其他方法一样,它适用于部分用户,但并非所有用户都具有某些用户之间的冲突.
This as with the others works for some but not all users with conflicts arising still with certain users.
我希望这篇文章中的某些wordpress插件开发人员可以提供帮助,并发布一种防弹方式,以便在我们的插件中使用wordpress和jquery而不会出现冲突问题.
I am hoping that from this post some of us wordpress plugin developers could help out and post a bullet proof way to use wordpress and jquery within our plugins without getting conflict issues.
谢谢
推荐答案
它不能与闭包一起使用吗?
Doesn't it work with a closure?
(function($){
// your plugin code
})(jQuery);
这篇关于子弹证明方法,以防止wordpress插件上的jquery冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!