jQuery 名称冲突解决办法

来源:互联网 发布:沙发的意思网络词语 编辑:程序博客网 时间:2024/05/17 01:57

jQuery 名称冲突

转自:http://www.w3school.com.cn/tiy/t.asp?f=jquery_noconflict

jQuery 使用 $ 符号作为 jQuery 的简介方式,而某些其他 JavaScript 库中的函数(比如 Prototype)同样使用 $ 符号。为了解决这个问题,jQuery 使用名为 noConflict() 的方法来解决该问题。

具体如下:

var jq=jQuery.noConflict(),帮助您使用自己的名称(比如 jq)来代替 $ 符号。

实例:

<html><head><script type="text/javascript" src="/jquery/jquery.js"></script><script type="text/javascript">var jq=jQuery.noConflict();jq(document).ready(function(){  jq("button").click(function(){    jq("p").hide();  });});</script></head><body><h2>This is a heading</h2><p>This is a paragraph.</p><p>This is another paragraph.</p><button type="button">Click me</button></body></html>


原创粉丝点击