Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将jQuery转换为无冲突模式_Javascript_Jquery - Fatal编程技术网

Javascript 将jQuery转换为无冲突模式

Javascript 将jQuery转换为无冲突模式,javascript,jquery,Javascript,Jquery,这是我正在使用的脚本 $(window).load(function() { $('#edifici, #artistici, #industriale, #fotovoltaico, #veterinaria, #architettonici').hide(); if (!!window.location.hash) { var hash = window.location.hash; var $content = $(hash); showContent($cont

这是我正在使用的脚本

$(window).load(function() {
$('#edifici, #artistici, #industriale, #fotovoltaico, #veterinaria, #architettonici').hide();

if (!!window.location.hash) {
    var hash = window.location.hash;
    var $content = $(hash);
    showContent($content)
}

$('.home').click(function () {
    var id = this.id.replace('mostra_', '');
    var $content = $('#' + id + ':not(:visible)');
    if ($('.current').length === 0) {
        showContent($content)
    } else {
        $('.current').fadeOut(600, function () {
            showContent($content)
        });
    }
});

function showContent(content) {
    content.fadeIn(600);
    $('.current').removeClass('current');
    content.addClass('current');
}
});
根据,为了在WordPress中使用它(其中jQuery处于无冲突模式),我将脚本修改为

jQuery.noConflict();

jQuery(window).load(function($) {
$('#edifici, #artistici, #industriale, #fotovoltaico, #veterinaria, #architettonici').hide();

if (!!window.location.hash) {
    var hash = window.location.hash;
    var $content = $(hash);
    showContent($content)
}

$('.home').click(function () {
    var id = this.id.replace('mostra_', '');
    var $content = $('#' + id + ':not(:visible)');
    if ($('.current').length === 0) {
        showContent($content)
    } else {
        $('.current').fadeOut(600, function () {
            showContent($content)
        });
    }
});

function showContent(content) {
    content.fadeIn(600);
    $('.current').removeClass('current');
    content.addClass('current');
}
});
不幸的是,它似乎不能正常工作。。。我做错了什么

jQuery.noConflict();
说明:放弃jQuery对$variable的控制

这意味着jQuery将不再使用$,因此它将清除与其他库的所有冲突

要在内部使用$,可以执行以下操作:

您可以将现有代码包装到匿名函数中,并将jQuery作为参数传递,例如:

(function ($) {

    // use $ here
    $('#hello').html('world');

})(jQuery);
或者使用jQuery提供的快捷方式:

jQuery(function($) {

    // use $
    $('#hello').html('world');

});
ready方法还传递jQuery对象:

jQuery(document).ready(function ($) {
    // ...
});

您是否尝试过将所有的
$
替换为
jQuery
。load
不会将对jQuery的引用传递给回调:。只有
.ready
会执行此操作。不会将
jQuery
作为参数调用,而是将
事件
对象作为参数调用。你把它和你的计划混在一起了。