如何在我的 Jquery 中删除冲突? [英] How Can I remove Conflict in my Jquery?
问题描述
我是 JQuery 新手,我在我的页面中使用了 2 个 jQuery.
I am new to JQuery And I have used 2 jQueries in my page.
对于第一个 JQuery,我的脚本是这样的:
For first JQuery my script is like this:
<script>
var jq = $.noConflict();
jq(function() {
jq( "#my_tabs" ).tabs({
event: "click" //click
});
});
</script>
现在,当我像这样使用第二个 jQuery 时,我丢失了我的第一个 jQuery.无法加载
Now when I use a second jQuery like this I lost my first jQuery. It's unable to load
<script type="text/javascript">
$(document).ready(function () {
$("#waterwheel-carousel-default").waterwheelCarousel();
$("#waterwheel-carousel-higharch").waterwheelCarousel({
startingWaveSeparation: -90,
waveSeparationFactor: .7,
centerOffset: 10,
startingItemSeparation: 120,
itemSeparationFactor: .9,
itemDecreaseFactor: .75
});
$("#waterwheel-carousel-horizon").waterwheelCarousel({
startingWaveSeparation: 0,
centerOffset: 30,
startingItemSeparation: 150,
itemSeparationFactor: .7,
itemDecreaseFactor: .75,
opacityDecreaseFactor: 1,
autoPlay: 1500
});
$("#waterwheel-carousel-flat").waterwheelCarousel({
itemSeparationFactor: 1,
itemDecreaseFactor: 1,
waveSeparationFactor: 1,
startingWaveSeparation: 0,
startingItemSeparation: 280,
centerOffset: 10,
opacityDecreaseFactor: .3,
autoPlay: 3000,
edgeReaction: 'reverse'
});
$("#waterwheel-carousel-vertical").waterwheelCarousel({
orientation: 'vertical',
startingItemSeparation: 100,
startingWaveSeparation: 40,
autoPlay: 2000
});
});
</script>
我正在使用两个 jQueries 进行图像滑动.谁能告诉我问题是什么?谢谢
I am using both jQueries for image sliding.. Can anyone tell me what the problem is? Thanks
推荐答案
这是你应该执行的 第二个 jQuery 脚本 $.noConflict()
on.
It is your 2nd jQuery script you should be performing $.noConflict()
on.
如果你这样做了;
<script src="http://code.jquery.com/jquery-1.7.js"></script>
<script>
var jq = $.noConflict();
jq(function() {
jq( "#my_tabs" ).tabs({
event: "click" //click
});
});
</script>
<script src="http://code.jquery.com/jquery-1.4.js"></script>
jQuery
和 $
都将指向 jQuery 1.4,而没有任何东西指向 jQuery 1.7.顺便说一句,如果您在加载 jQuery 1.4 后运行 $.noConflict
again,jQuery
将引用 1.4,但 $
将是未定义的.
Both jQuery
and $
will point to jQuery 1.4, and nothing will refer to jQuery 1.7. Incidentally, if you were to run $.noConflict
again after loading jQuery 1.4, jQuery
would reference 1.4, but $
would be undefined.
但是,如果你这样做:
<script src="http://code.jquery.com/jquery-1.7.js"></script>
<script src="http://code.jquery.com/jquery-1.4.js"></script>
<script>
var jq = $.noConflict();
jq(function() {
jq( "#my_tabs" ).tabs({
event: "click" //click
});
});
</script>
$
将引用 jQuery 1.7,但 jQuery
将指向 jQuery 1.4(您的 jq
变量也是如此).
The $
will refer to jQuery 1.7, but the jQuery
will point to jQuery 1.4 (as will your jq
variable).
你可能想看看 $.noConflict(true)
;释放 jQuery
和 $
变量;所以你可以做这样的事情;
You may want to look at the $.noConflict(true)
; which releases both the jQuery
and $
variables; so you can do something like this;
<script src="http://code.jquery.com/jquery-1.7.js"></script>
<script src="http://code.jquery.com/jquery-1.4.js"></script>
<script>
var jq = $.noConflict(true);
jq(function() {
jq( "#my_tabs" ).tabs({
event: "click" //click
});
});
</script>
那么 $
和 jQuery
都会指向 jQuery 1.7,只有你的 jq
变量会指向 jQuery 1.4
Then both the $
and jQuery
will point to jQuery 1.7, and only your jq
variable will point to jQuery 1.4
这篇关于如何在我的 Jquery 中删除冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!