当前位置: 移动技术网 > IT编程>开发语言>Jquery > jQuery 名称发生冲突怎么办【问题】

jQuery 名称发生冲突怎么办【问题】

2019年07月12日  | 移动技术网IT编程  | 我要评论

【问题】jquery 名称发生冲突怎么办?

【答案】jquery 使用 $ 符号作为 jquery 的简介方式。某些其他 javascript 库中的函数(比如 prototype)同样使用 $ 符号。jquery 使用名为 noconflict() 的方法来解决该问题。

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

【还未能理解透彻】

<!doctype html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$.noconflict();
jquery(document).ready(function(){
  jquery("button").click(function(){
    jquery("p").text("jquery 仍在运行!");
  });
});
</script>
</head>

<body>
<p>这是一个段落。</p>
<button>测试 jquery</button>
</body>
</html>

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网