Jquery plugin conflicts

假如想象 提交于 2019-12-11 03:58:03

问题


How do you guys resolve conflicts between Jquery plugins. A conflict would be a situation where two or more Jquery plugins (such as a file upload plugin) work properly alone but result in errors or unintended behavior when you include a second plugin.

I have this problem right now and I am considering using an iframe to isolate sections of my page from everything else. But I want to avoid this if possible to work out these conflicts.

Auditing the plugin code is not feasible its mountains of code and there are short development times to consider.

I can't use jquery.noConflict because I would have to fire it and then replace the $ with Jquery in ever line of my code. Editing the plugins is not feasible. I thought jquery.noConflict didn't work for plugins? It only works for javascript/jquery libraries? I'm not reffering to libraries. Just plugins like sliders, galleries, fileuploaders etc etc.

I used:

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

});

Already..


回答1:


After some digging around on the web I found some resources

  1. Jquery Plugin conflict

  2. How do I solve this jQuery plugins conflict?

  3. http://forum.jquery.com/topic/jquery-plugins-conflict

And the last one http://www.jotform.com/help/130-Fixing-Jquery-Plugin-Conflicts-jCarousel

It seems that everyone suggest to use noconflict but except for the last one who said it worked - I don't see a reason it should work, since in documentations JQuery explains that it was meant for libraries that don't use JQuery but collide with it. ( see the 3rd resource I pasted here).

Anyway, it seems as if the best option is to dive into the code and modify it.




回答2:


i had an issue with jquery conflict, but my case was i had also used prototype.js. i worked out a solution for that. here is a pointer checkout if it helps.

jquery conflict occurs when "$" is also used by some other plugins. hence we need to define jQuery.noConflict

so that all the methods are called using some other reference in this case 'jQuery'.

try include the scripts files on the page as follows.

  1. include all the jQuery files (library and all plugins which are dependent on jquery).
  2. fire jQuery.noConflict();
  3. include all other libraries/ plugins.
  4. wherever jquery methods are called use "jQuery" istead of "$"

hope this helps you out..



来源:https://stackoverflow.com/questions/12115174/jquery-plugin-conflicts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!