jQuery没有冲突模式如何工作?

任何人都可以一劳永逸地向我解释jQuery没有冲突模式。 根据我的阅读,它将解决jquery脚本冲突的问题,但我不确定如何实现它以及它正在解决的冲突?

我在这里使用了很多脚本,这些脚本随着时间的推移而累积起来。 然而现在,这有点乱,我想知道是否有人可以建议我如何摆脱脚本之间的任何冲突问题。

目前,’datepicker’脚本不起作用。 但是,如果我将’datepicker’向上移动到页面上,它确实有效,但是其他东西没有,我尝试了所有组合,并且不能让所有脚本同时运行。

这是我的所有脚本(我删除了任何html或css,希望尽可能清楚)。 也许有些可以组合在一起使它变得更加整洁? jQuery冲突模式会解决这些冲突问题吗?

我的代码如下:

    $(document).ready(function(){ $('.menuitem img').animate({width: 155, 'padding-top' : 100}, 0); $('.menuitem').mouseover(function(){ gridimage = $(this).find('img'); gridimage.stop().animate({width: 200, 'padding-top': 0}, 500); }).mouseout(function(){ gridimage.stop().animate({width: 155, 'padding-top': 100}, 300); }); });    $(document).ready(function(){ //Examples of how to assign the Colorbox event to elements $(".group1").colorbox({rel:'group1'}); $(".group2").colorbox({rel:'group2', transition:"fade"}); $(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"}); $(".group4").colorbox({rel:'group4', slideshow:true}); $(".ajax").colorbox(); $(".youtube").colorbox({iframe:true, innerWidth:640, innerHeight:390}); $(".vimeo").colorbox({iframe:true, innerWidth:500, innerHeight:409}); $(".iframe").colorbox({iframe:true, width:"80%", height:"80%"}); $(".inline").colorbox({inline:true, width:"auto"}); $(".callbacks").colorbox({ onOpen:function(){ alert('onOpen: colorbox is about to open'); }, onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); }, onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); }, onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); }, onClosed:function(){ alert('onClosed: colorbox has completely closed'); } }); $('.non- retina').colorbox({rel:'group5', transition:'none'}) $('.retina').colorbox({rel:'group5', transition:'none', retinaImage:true, retinaUrl:true}); //Example of preserving a JavaScript event for inline calls. $("#click").click(function(){ $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here."); return false; }); });   var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-32843811-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();   $(document).ready(function(){ // at first hide divs $(".slidingDiv").hide(); $(".slidingDiv2").hide(); $(".slidingDiv3").hide(); $(".slidingDiv4").hide(); $(".slidingDiv5").hide(); $(".slidingDiv6").hide(); $(".slidingDiv7").hide(); $(".slidingDiv8").hide(); $(".slidingDiv9").hide(); $(".slidingDiv10").hide(); $(".show_hide").show(); $('.show_hide').click(function(){ $(".slidingDiv").slideToggle(); return false; }); $('.first_s').live('click', function(){ $(".slidingDiv2").slideToggle(); return false; }) $('.second_s').live('click', function(){ $(".slidingDiv3").slideToggle(); return false; }) $('.third_s').live('click', function(){ $(".slidingDiv4").slideToggle(); return false; }) $('.fourth_s').live('click', function(){ $(".slidingDiv5").slideToggle(); return false; }) $('.fifth_s').live('click', function(){ $(".slidingDiv6").slideToggle(); return false; }) $('.sixth_s').live('click', function(){ $(".slidingDiv7").slideToggle(); return false; }) $('.seventh_s').live('click', function(){ $(".slidingDiv8").slideToggle(); return false; }) $('.eighth_s').live('click', function(){ $(".slidingDiv9").slideToggle(); return false; }) $('.ninth_s').live('click', function(){ $(".slidingDiv10").slideToggle(); return false; }) });     $(function() { $( "#datepicker, #datepicker2" ).datepicker({ changeMonth: true, changeYear: true }); });   

以下是我正在运行Chrome浏览器控制台的错误:

 GET http://www.paycoservices.co.uk/ahkerrigan-light-webfont.woff 404 (Not Found) Simply- Umbrella-Registration.asp:215 Resource interpreted as Font but transferred with MIME type application/octet-stream: "http://www.paycoservices.co.uk/ahkerrigan-light-webfont.ttf". Simply-Umbrella- Registration.asp:839 GET http://www.paycoservices.co.uk/pt_sans-web-bold-webfont.woff 404 (Not Found) Simply- Umbrella-Registration.asp:450 Resource interpreted as Font but transferred with MIME type application/octet-stream: "http://www.paycoservices.co.uk/pt_sans-web-bold-webfont.ttf". Simply-Umbrella- Registration.asp:839 GET http://www.paycoservices.co.uk/onlineforms/webform/scripts/wufoo.js 404 (Not Found) Simply-Umbrella-Registration.asp:839 1. Uncaught TypeError: Object [object Object] has no method 'datepicker' Simply-Umbrella- Registration.asp:163 [cycle] terminating; zero elements found by selector 

jQuery no conflict mode适用于页面中包含多个javascript库的情况,每个javascript库都定义了一个名为$的全局变量。 在这种情况下, jQuery.noConflict()$ value的值更改回由不同库提供的旧值,并且您必须在代码中使用变量jQuery而不是$来使用jQuery函数。

话虽如此,如果你包含了提供$变量的nother库,那么no conflict模式可能有所帮助,你必须重写$ jQuery所有用法。

我决定去寻找一个非常简单的日期选择器,它不回复任何东西,所以去了这个,这与我的其他脚本一起工作。 http://www.splinter.com.au/javascript-date-picker-that-doesnt-sucktm/