gpt4 book ai didi

javascript - 脚本引用导致冲突

转载 作者:行者123 更新时间:2023-11-30 08:11:59 25 4
gpt4 key购买 nike

我有代码 1,它在头部执行:

<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>

然后我有代码 2:

<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script src="livesearch.js" type="text/javascript"></script>

问题是,当我输入最后一个引用(代码 2)时,第一个引用不再起作用。我做错了什么?

(出于某种原因,代码 2 对 jquery 1.7 没有反应)

最佳答案

您需要的是:jQuery.noConflict .

If necessary, we can free up the jQuery name as well by passing true as an argument to the method. This is rarely necessary, and if we must do this (for example, if we need to use multiple versions of the jQuery library on the same page)

例如:

<script class="jsbin" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="javascript">
// now you alias the v1.7 jQuery to jQuery17
jQuery17 = jQuery.noConfict(true);
</script>

<script src="http://code.jquery.com/jquery-1.4.3.min.js"></script>
<script type="javascript">
// now you alias the v1.4 jQuery to jQuery14
jQuery14 = jQuery.noConfict(true);
</script>

并将您的两部分代码放在不同的范围内。

(function($){
//put your codes here which need jQuery 1.7 version
.....
})(jQuery17);

(function($){
//put your codes here which need jQuery 1.4 version
.....
})(jQuery14);

关于javascript - 脚本引用导致冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8961120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com