jquery类库和其他js类冲突的解决方法
2016-04-19 09:51
519 查看
prototype和jquery冲突了。
prototype的选择器是"$"
jquery的选择器也是"$"
解决方法是:
将jquery的"$"改为其他的,如"$j"。
先将所有需要导入的js导入后,再在运行脚本处,加上一行:$j = jQuery.noConflict();
其后将其所用特效的所有"$"都改为"$j"
问题解决。
<script language="javascript" type = "text/javascript" src="content/script/prototype.lite.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/moo.fx.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/moo.fx.pack.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
$j = jQuery.noConflict();
function slideSwitch() {
var $jactive = $j('#slideshow IMG.active');
if ($jactive.length == 0) $jactive = $j('#slideshow IMG:last');
// use this to pull the images in the order they appear in the markup
var $jnext = $jactive.next().length ? $jactive.next()
: $j('#slideshow IMG:first');
// uncomment the 3 lines below to pull the images in random order
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$jactive.addClass('last-active');
$jnext.css({ opacity: 0.0 })
.addClass('active')
.animate({ opacity: 1.0 }, 1000, function() {
$jactive.removeClass('active last-active');
});
}
$j(function() {
setInterval("slideSwitch()", 4000);
});
</script>
prototype的选择器是"$"
jquery的选择器也是"$"
解决方法是:
将jquery的"$"改为其他的,如"$j"。
先将所有需要导入的js导入后,再在运行脚本处,加上一行:$j = jQuery.noConflict();
其后将其所用特效的所有"$"都改为"$j"
问题解决。
<script language="javascript" type = "text/javascript" src="content/script/prototype.lite.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/moo.fx.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/moo.fx.pack.js"></script>
<script language="javascript" type = "text/javascript" src="content/script/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
$j = jQuery.noConflict();
function slideSwitch() {
var $jactive = $j('#slideshow IMG.active');
if ($jactive.length == 0) $jactive = $j('#slideshow IMG:last');
// use this to pull the images in the order they appear in the markup
var $jnext = $jactive.next().length ? $jactive.next()
: $j('#slideshow IMG:first');
// uncomment the 3 lines below to pull the images in random order
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$jactive.addClass('last-active');
$jnext.css({ opacity: 0.0 })
.addClass('active')
.animate({ opacity: 1.0 }, 1000, function() {
$jactive.removeClass('active last-active');
});
}
$j(function() {
setInterval("slideSwitch()", 4000);
});
</script>
相关文章推荐
- jQuery转换JS原生代码
- jquery ui autocomplete
- 2016/04/18 ①注册 注册处理 ② 审核 审核处理 ③登录 登录处理 ④需要jquery-1.11.2.min.js DBDA.php
- jquery中获取元素的几种方式小结
- Jquery Validate验证
- jQuery Ajax 调用WebService实例详解
- jQuery实现选项联动轮播效果【附实例】
- Jquery实现的简单轮播效果【附实例】
- jquery使用Cookie和JSON记录用户最近浏览历史
- jQuery移动端日期(datedropper)和时间(timedropper)选择器附源码下载
- jQuery 追加元素方法
- jQuery
- not jquery
- 使用Jquery serialize序列化Form表单
- jquery tmpl 详解
- python开发学习-day13(js、jQuery)
- Jquery遍历方法
- Jquery选择器汇总
- a毛 jquery 学习记 5 基础DOM和CSS操作3
- Jquery获取和修改dom元素的属性值