两个jQuery插件在同一页面上发生冲突 [英] Two jQuery plugin conflicting on the same page

查看:146
本文介绍了两个jQuery插件在同一页面上发生冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个文件上有两个jQuery插件.一个是jquery.autocomplete.js,另一个是jquery.thumbnailScroller.js.

I have two jQuery Plugins working on the same file. One is jquery.autocomplete.js and the other is jquery.thumbnailScroller.js .

问题是当我在同一个文件上同时使用这两个文件时,自动完成功能根本无法在thumbnailScroller上正常工作,但是在没有thumbnailScroller插件的情况下同样可以正常工作.

The problem is when I am using both on same file, autocomplete is not working at all an thumbnailScroller is working and but the same is working well without thumbnailScroller plugin.

现在,当我浏览js文件时,两个文件中都显示了$.fn..但是,我不知道是因为这个原因还是其他原因造成的问题.

Now, when I was browsing thru the js files, I got $.fn. in both files. But, I dont know is the problem because of this or anything else.

我也在google和stackoverflow中进行了搜索,但是我没有找到合适的解决方案. 请指导我

I had searched in google and stackoverflow also, but I failed to get the proper solution. Please guide me

推荐答案

有一些方法可以避免jquery中的冲突. 我总是喜欢这样

There are some ways for avoiding conflict in jquery. I always do like this

var $k = jQuery.noConflict();

并为任何一个插件的每个$函数使用$ k.请勿在插件js文件中执行此操作.对您的实施页面执行此操作,例如

and use $k for every $ functions for any one plugin. Not do this in plugin js files. Do this for your implementation page, like,

$k("#id").autocomplete({... 

致谢

iijb

这篇关于两个jQuery插件在同一页面上发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆