jQuery - noContribute() ???
jQuery? $ ??? jQuery? ??? ?????.
?? JavaScript ???????? $ ??? ??? ???? ??? ????
?? JavaScript ??????? MooTools, Backbone, Sammy, Cappuccino, Knockout, JavaScript MVC, Google Web Toolkit, Google Closure, Ember, Batman ? Ext JS? ?????.
??? ????? ? ??? $ ??? ?? ??? ?????(jQuery? ?????). ??? ?? ??? ???? ? ?? ?? ?? ?????? ???? ?? ???? ??? ??? ? ????.
jQuery ?? ? ??? ???? noContribute() ???? ??????.
noConstrict()? ??
noConstrict()? ??? ? ??? ????? ?????. ?, ??? ???? ?? jQuery ????, ?? ??? ??? jQuery? ??? ? ??? ????. ? ???? ?? ?? ??? jQuery ??? ??/???? ?? ??? ???? ??? ????. ????? ? ?? ??? ????. ? ?? ???? ???? ??? ?? ??? jQuery ?????? ????, ??? ?? ????? ?? ??? jQuery ?????? ?????. ? ?? ???? ?? ?? ???? ?? ???? ????. ???? ?? ?? ??? ??? ?? ??? jQuery ?????? ???? ?? ??? ??? ?? ??? jQuery ?????? ?????. ? ?? ?? jQuery ??/??? ?? ??? ???? ???. ?????? jQuery.noConstrict()? ? ??? ???? ? ??? ???.
jQuery noConstrict() ???
noConstrict() ???? $ ???? ?? ??? ???? ?? ?????? ??? ? ??? ???.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $.noConflict(); jQuery(document).ready(function(){ jQuery("button").click(function(){ jQuery("p").text("jQuery在工作!"); }); }); </script> </head> <body> <p>看我的變化</p> <button>點(diǎn)我</button> </body> </html>
??? ?? ???? ?? jQuery? ?????.
???? ??? ?? ? ????:
var jq = $.noConflict(); jq(document).ready(function(){ jq("button").click(function(){ jq("p").text("jQuery 仍然在工作!"); }); });
jQuery ?? ??? $ ???? ???? ? ???? ???? ?? ?? ?? $ ??? Ready ???? ??? ??? ? ????. ? ???? ?? ???? $ ??? ??? ? ??? ?? ????? ??? "jQuery"? ???? ???.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $.noConflict(); jQuery(document).ready(function($){ $("button").click(function(){ $("p").text("這是覆蓋的文字"); }); }); </script> </head> <body> <p>這是一段文字</p> <button>點(diǎn)擊顯示</button> </body> </html>