解决jQuery和其它库的冲突
2010-08-16 17:08
337 查看
在jQuery库中,几乎所有的插件都被限制在它的命名空间里。通常,全局(global)对象被很好地存储在jQuery命名空间里,因此当把jQuery和其他JavaScript库(例如Prototype、MooTools或YUI)一起使用时,不会引起冲突。
1.jQuery库在其他库这后导入
在其他库和jQuery库都被加载完毕后,可以在任何时候调用jQuery.noConflict()函数来将变量$的控制权移交给其它javaScript库。如:
jQuery先导入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>冲突解决</title>
<!--先导入jQuery -->
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<!--后导入其他库 -->
<script src="js/prototype.js" type="text/javascript"></script>
</head>
<body>
<p id="pp">test prototype</p>
<p >test jQuery</p>
<script type="text/javascript">
jQuery(function(){ //直接使用 jQuery ,没有必要调用"jQuery.noConflict()"函数。
jQuery("p").click(function(){
alert( jQuery(this).text() );
});
});
$("pp").style.display = 'none'; //使用prototype
</script>
</body>
</html>
有了这些方法解决冲突,就可以放心在项目中引入jQuery了。
1.jQuery库在其他库这后导入
在其他库和jQuery库都被加载完毕后,可以在任何时候调用jQuery.noConflict()函数来将变量$的控制权移交给其它javaScript库。如:
jQuery先导入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>冲突解决</title>
<!--先导入jQuery -->
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<!--后导入其他库 -->
<script src="js/prototype.js" type="text/javascript"></script>
</head>
<body>
<p id="pp">test prototype</p>
<p >test jQuery</p>
<script type="text/javascript">
jQuery(function(){ //直接使用 jQuery ,没有必要调用"jQuery.noConflict()"函数。
jQuery("p").click(function(){
alert( jQuery(this).text() );
});
});
$("pp").style.display = 'none'; //使用prototype
</script>
</body>
</html>
有了这些方法解决冲突,就可以放心在项目中引入jQuery了。
相关文章推荐
- 解决jquery与zepto等其它库冲突兼容的问题
- jquery与其它js文件冲突解决办法
- 解决jQuery和其它库的冲突
- jquery学习笔记(3)-----jquery与其它库冲突解决
- Jquery与其它js框架(MooTools以及Prototype、Dojo、YUI等等)之间共享冲突的解决办法
- jQuery与其它库冲突的解决方法
- (五)解决jQuery和其它库的冲突
- jQuery源码分析:如何解决jQuery、$关键字与其它脚本框架的冲突问题?
- 用闭包解决jQuery和其它框架的$符号冲突的问题
- jQuery与其它库冲突的解决方法
- 解决jquery与其它库的冲突
- jquery使用$与其它js框架的冲突解决办法
- 解决jQuery和其它库的冲突
- jQuery与其它库冲突 4000 的解决方法
- 解决jquery 与其它库的冲突
- 解决jQuery和其它库的冲突
- JQuery选取器与其它JS框架冲突的解决方法 确保jQuery不会与其他库的$对象发生冲突
- jquery和其它js库起冲突的解决方法
- 锋利的jQuery学习笔记(二)—————解决jQuery和其它库的冲突
- jQuery与其它库冲突的解决方法