jQuery调用的问题

<html>
<head>
    <meta charset="utf-8">
    <style type="text/css">
        div {
            background: magenta;
            width: 500px;
            height: 300px
        }
    </style>
    <script src="js/jquery-1.8.3.js"></script>
    <script>
        var z = jQuery.noConflict();
        jQuery(function(){
            alert("hello");
        })
        z(function () {
            alert("world");
        })
    </script>
</head>
<body>
    <div></div>
</body>
</html>

代码如上图,用了noConflict()方法,但是还是可以用jQuery来调用方法,用z调用也可以,不是应该不能用jQuery调用了吗?

阅读 1.6k
3 个回答

你应该这么用:

$.noConflict(true)
If necessary, you can free up the jQuery name as well by passing true as an argument to the method. This is rarely necessary, and if you must do this (for example, if you need to use multiple versions of the jQuery library on the same page), you need to consider that most plug-ins rely on the presence of the jQuery variable and may not operate correctly in this situation.
http://api.jquery.com
  1. noConflict作用于$,而不是jQuery
  2. 你的代码里面并没有$的冲突
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题