jQuery 名稱沖突的解決方法
更新時間:2011年04月08日 00:06:11 作者:
jQuery 使用 $ 符號作為 jQuery 的簡介方式。某些其他 JavaScript 庫中的函數(shù)(比如 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>
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>
相關文章
Layer組件多個iframe彈出層打開與關閉及參數(shù)傳遞的方法
今天小編就為大家分享一篇Layer組件多個iframe彈出層打開與關閉及參數(shù)傳遞的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09
Winform客戶端向web地址傳參接收參數(shù)的方法
這篇文章主要介紹了Winform客戶端向web地址傳參接收參數(shù)的方法的相關資料,需要的朋友可以參考下2016-05-05
基于JavaScript實現(xiàn)鼠標懸浮彈出跟隨鼠標移動的帶箭頭的信息層
這篇文章主要介紹了基于JavaScript實現(xiàn)鼠標懸浮彈出跟隨鼠標移動的帶箭頭的信息層 的相關資料,需要的朋友可以參考下2016-01-01

