2012-03-16 99 views
0

我正在使用LightBox2获取简单的图片库。我设法使它工作,但现在它与我从我的页面引用的另一个JavaScript脚本文件冲突。lightbox2与脚本冲突

我的脚本使用$(document).ready(function() {

我不知道这是否是相关或不但是我知道,在一个点浏览器的调试器抱怨它。

对此有何见解?

============================================== ============== 我包含了部分产生错误的代码。虽然这工作正常。

var currs = {};

jQuery.noConflict();

jQuery(document).ready(function() { 
    var marketTypeSel = document.getElementById("selMarketType"); 
    var propertyTypeSel = document.getElementById("selPropertyType"); 
    var propertyStatusSel = document.getElementById("selPropertyStatus"); 
    var zoneSel = document.getElementById("selZone"); 
    var locSel = document.getElementById("selLocalities"); 
    var currSel = document.getElementById("selCurrency"); 
    var priceFromSel = document.getElementById("selPriceFrom"); 
    var priceToSel = document.getElementById("selPriceTo"); 

    //var data = {}; 

    marketTypeSel.length = 0; 
    propertyTypeSel.length = 0; 
    propertyStatusSel.length = 0; 
    zoneSel.length = 0; 
    locSel.length = 0; 
    currSel.length = 0; 

    jQuery.ajax({ 
     type: "POST", 
     url: "/Search/LoadInitSearchParameters", 
     //data: data, 
     dataType: "json", 
     success: function (result) { 
+0

它在所有浏览器中是否存在冲突?手段通常在IE中发生问题。 – 2012-03-16 09:35:29

+0

是的所有浏览器:/ – Jonny 2012-03-16 09:36:51

+0

我同意@devtut。你试过jQuery.noConflict()吗? – 2012-03-16 09:39:43

回答

4

可以使用,当使用jQuery的下方

var Jk = jQuery.noConflict(); 
Jk(document).ready(function(){ 


}); 
+0

尝试已经没有工作:/ – Jonny 2012-03-16 09:45:07

+0

是的,设法使它工作有一个错误在我的js文件,今天糟糕的一天!非常感谢 – Jonny 2012-03-16 16:36:19

0

这样没有冲突,你可以使用

​​

JQuery(document).ready(function(){ 


}); 

简单地使用jQuery,而不是$ jqu ery

0

如果它仍然不起作用,做一件事情就是在关闭身体标记之前添加所有脚本ref,而不是头标记。我面临同样的问题,这个技巧对我来说很有用。

像下面

<body> 
     <div>Dummy Data</div> 
     <div>Dummy Data</div> 
     <script src="/App_Themes/lib/jquery-1.6.2.min.js" type="text/javascript"></script> 
     <script src="/App_Themes/lib/jquery.jcarousel.js" type="text/javascript"></script> 
     <script src="/App_Themes/lib/jquery.easing.1.2.js" type="text/javascript"></script> 
     //Also lightbox ref 
</body> 
+0

nope:/ ...什么都不会工作...我会尝试类似于灯箱的东西 – Jonny 2012-03-16 10:06:46

0

这是Lightbox2 2.8.1。

当你使用jQuery(document).ready(function() {});这将停止从初始化灯箱。

我发现我必须添加lightbox.init(),因为我的代码正在停止lightbox2的加载。

$(function() { 
    lightbox.init(); 
    // other code 
}