温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Prototype与jQuery冲突|兼容性问题解决方法

发布时间:2020-07-31 04:52:04 来源:网络 阅读:229 作者:chunzhisu 栏目:web开发

<!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>prototype与jQuery冲突解决4</title>

<!-- 引入 prototype  -->

<script src="/ajaxjs/prototype-1.6.0.3.js" type="text/javascript"></script>

<!-- 引入 jQuery  -->

<script src="/ajaxjs/jquery-1.3.1.js" type="text/javascript"></script>

</head>

<body>

<p id="pp">test---prototype</p>

<p >test---jQuery</p>


<script type="text/javascript">

jQuery.noConflict(); //将变量$的控制权让渡给prototype.js

(function($){ //定义匿名函数并设置形参为$

$(function(){ //匿名函数内部的$均为jQuery

$("p").click(function(){ //继续使用 $ 方法

alert($(this).text());

});

});

})(jQuery); //执行匿名函数且传递实参jQuery


$("pp").style.display = 'none';//使用prototype

</script>

</body>

</html>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI