鍍金池/ 問(wèn)答/HTML/ jQuery調(diào)用的問(wèn)題

jQuery調(diào)用的問(wèn)題

<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來(lái)調(diào)用方法,用z調(diào)用也可以,不是應(yīng)該不能用jQuery調(diào)用了嗎?

回答
編輯回答
神經(jīng)質(zhì)
  1. noConflict作用于$,而不是jQuery
  2. 你的代碼里面并沒(méi)有$的沖突
2018年4月11日 10:03
編輯回答
久愛(ài)她

noConflict 方法只是對(duì)$起作用,而不是jQuery

參見(jiàn):

http://api.jquery.com/jQuery....

2017年7月22日 10:20
編輯回答
神經(jīng)質(zhì)

你應(yīng)該這么用:

$.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
2018年6月8日 21:41