0

我正在使用 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) {
4

4 回答 4

4

您可以像下面这样使用没有冲突的jquery

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


});
于 2012-03-16T09:32:31.647 回答
0

您可以使用

 jQuery.noConflict();

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


});

或者

JQuery(document).ready(function (){


});

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

于 2012-03-16T09:39:52.157 回答
0

如果仍然无法正常工作,请在关闭 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>
于 2012-03-16T09:56:09.343 回答
0

这适用于 Lightbox2 2.8.1。

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

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

$(function() {
    lightbox.init();
    // other code
}
于 2015-08-08T03:13:41.760 回答