×

『jQuery』名称冲突使用noConflict方法解决

作者:Terry2017.02.14来源:Web前端之家浏览:11897评论:0
关键词:JQueryJS
JQuery 使用 $ 符号作为 jQuery 的简介方式。
某些其他 javascript 库中的函数(比如 prototype)同样使用 $ 符号。
jquery 使用名为 noConflict() 的方法来解决该问题。
varjq=JQuery.noConflict(),帮助使用自己的名称(比如 jq)来代替 $ 符号。
复制代码 代码如下:

<html>
<head>
<scripttype="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>

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1487001600677.html

网友评论文明上网理性发言已有0人参与

发表评论: