『jQuery』名稱沖突使用noConflict方法解決
更新時間:2013年04月22日 09:45:24 作者:
jQuery 使用 $ 符號作為 jQuery 的簡介方式。某些其他 JavaScript 庫中的函數(shù)(比如 Prototype)同樣使用 $ 符號,這樣就會發(fā)生名稱沖突,使用名為 noConflict() 的方法來解決該問題
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>
某些其他 JavaScript 庫中的函數(shù)(比如 Prototype)同樣使用 $ 符號。
jQuery 使用名為 noConflict() 的方法來解決該問題。
var jq=jQuery.noConflict(),幫助使用自己的名稱(比如 jq)來代替 $ 符號。
復(fù)制代碼 代碼如下:
<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>
您可能感興趣的文章:
相關(guān)文章
jQuery使用animate創(chuàng)建動畫用法實例
這篇文章主要介紹了jQuery使用animate創(chuàng)建動畫用法,可實現(xiàn)點擊鏈接文字隱藏及顯示文字的功能,實例分析了jquery中toggle與animate方法的使用技巧,需要的朋友可以參考下2015-08-08
jQuery EasyUI API 中文文檔 - Calendar日歷使用
jQuery EasyUI API 中文文檔 - Calendar日歷使用,需要的朋友可以參考下。
2011-10-10
基于Jquery的將DropDownlist的選中值賦給label的實現(xiàn)代碼
使用Jquery 將DropDownlist的選中值賦給label的代碼,需要的朋友可以參考下。
2011-05-05
jquery下為Event handler傳遞動態(tài)參數(shù)的代碼
在jquery cook book里看到一篇給event handler傳遞動態(tài)參數(shù)的文章 感覺挺實用的 跟大家分享下
2011-01-01 
