lightbox2与脚本冲突

lightbox2 is conflicting with scripts

本文关键字:冲突 脚本 lightbox2      更新时间:2023-09-26

我将LightBox2用于一个简单的图像库。我设法使它工作,但现在它与我在页面中引用的另一个javascript脚本文件冲突。

我的脚本正在使用$(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) {

您可以在下面使用没有冲突的jquery

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

});

您可以使用

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

});

JQuery(document).ready(function (){

});

使用jquery 时,只需使用jQuery而不是$

如果仍然不起作用,请在关闭body标记之前添加所有脚本引用,即代替head标记。我面临着同样的问题,这个技巧对我来说很有效

像低于

   <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>

这适用于Lightbox2 2.8.1。

当您使用jQuery(document).ready(function () {});时,这将阻止灯箱初始化。

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

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