琛?????褰?锛??瑰?誨?瑰???褰?杩?琛?璺寵漿
|
涓?.缂???JavaScript搴?瑕?娉ㄦ??????棰?
涓轟?璁╄??宸辯??JS搴???寤虹???村??浼?????????锛???浠?缂???JS搴??惰?娉ㄦ??涓ゆ?歸?㈢????瀹癸?
1.涓?瑕?浣跨?ㄧ????妫?娴?锛???瑕?浣跨?ㄨ?藉??妫?娴?
?變?娴?瑙??ㄧ??绫誨????????澶?澶?锛?浠ュ??涓??????扮??娴?瑙??ㄥ?虹?幫???浠?涓????芥???ュぇ?????堕?村???????誨??璺墊?娴???绉???????娴?瑙??ㄣ??"娴?瑙??ㄦ?娴?"涔???"????妫?娴?"??甯歌?璁や負??涓?绉???璇?????娉?锛?娴?瑙??ㄦ?娴?????浣沖??璺墊???藉??妫?娴?锛???甯鎬?琚?绉頒負瀵矽薄妫?娴?锛????????ㄤ唬???ц?涔???妫?娴???涓?????瀵矽薄or?規????????????涓???渚?璧?浜?浣?瀵瑰??涓?娴?瑙??ㄥ?鋒????浜??瑰????浜?瑙c??濡???蹇?椤葷??瀵矽薄???規?瀛?????d?璇存??娴?瑙??ㄨ?藉?浣跨?ㄥ??锛???涓?浠g??涔???浠ユ???ч????ц????藉??妫?娴?浣跨??lt;if(xxx.xxxx)>???瑰?
[javascript] view plain copy print ?
[javascript] view plain copy print ?
- // JavaScript Document?
- if(document.body && document.body.getElementsByTagName){?
- ??? //浣跨??ocument.body.getElementsByTagName??浠g???
- ??? }?
- // JavaScript Document?
- if(document.body && document.body.getElementsByTagName){?
- ??? //浣跨??ocument.body.getElementsByTagName??浠g???
- ??? }?
// JavaScript Document if(document.body && document.body.getElementsByTagName){ //浣跨??ocument.body.getElementsByTagName??浠g?? }
2.浣跨?ㄥ?藉??绌洪??
褰?浣跨?ㄥ?涓?js搴???浠舵?訛?涓轟??垮???ㄨ??ㄦ?朵???js搴???浠剁???????芥?扮???茬??锛?涓???浼?浣跨?ㄥ?藉??绌洪?存?ヨВ?熾??JavaScript?????????芥?幫?浣???浣跨?ㄦ????涓?涓???杞界???芥?幫?涓???????杞斤?涓?浼????????幫??????芥?闆??瀛?锛?锛? ??涓?涓?????琚???杞斤???涓?涓?灏變?琚?璋??ㄥ?般????浠ヤ?浣跨?ㄥ?藉??绌洪?寸??璇?锛?灏卞?瀹規?????闆?????芥?闆?茬??????棰???
????? 浣跨?ㄥ?藉??绌洪?寸??涓ょ?瑰????锛???涓??э?涓??變韓??
??涓??э?????涓?涓???涓???浜????藉??绌洪?寸????瀛?锛?濡?Google Maps?ㄦ????????璇?绗?腑?芥坊??浜?G??缂?锛?锛?娉ㄦ??js??澶у???????????
涓??變韓锛?涓??變韓???崇??浠?涔??戒??變韓锛?褰?浣???寤鴻??宸辯??$?芥?版?朵????戒?涓???????搴?(濡?Prototype)涓???$?芥?闆?????茬????瀵艱??rototype涓???$??娉?浣跨???涓轟?涓?涓???????涓?浜?搴?锛?jQuery??prototype锛??????朵?宸叉????涓?浜??芥?闆?茬??锛?浣跨?ㄥ?垮???芥?版?ュ???頒唬????涓??變韓??濡?锛?瑕?淇?璇?????浣???宸變嬌?ㄨ?涓?$()?芥?幫?浣???浠ヤ嬌?ㄤ?涓?JS灏???宸с??
//?垮???芥?? (function(){
//code,杩?琛???浠g??
})();
娉ㄦ??锛?()??avaScript涓???涓ょ???涔?锛?涓???杩?绠?绗??浜???????绗???
涓??㈠?垮???芥?伴??瑕?璇存??涓ょ?癸?
???? ??绾㈣?叉???烽????涓?涓??垮???芥?幫?绾㈣?叉???蜂唬琛ㄥ???詫?琛ㄧず???㈢???芥?版??涓?涓??ㄥ??锛?
???? ?$豢?叉???瘋〃绀轟?涓?杩?绠?绗??琛ㄧず绾㈣?叉???烽???㈢???芥?拌?杩?琛?锛??稿?浜?瀹?涔?瀹?涓?涓??垮???芥?闆??灏辮?╁???存?ヨ?琛???
浜?.缂???JavaScript搴?妯℃??
1.??浠ヤ嬌?ㄤ??㈢??妯℃?挎?ョ?????宸辯??JavaScript搴?
[javascript] view plain copy print ?
[javascript] view plain copy print ?
- <SPAN style="FONT-FAMILY: FangSong_GB2312">//JavaScript搴?妯℃?誇唬???
- ??? (function (){?
- ??????? function $(){?
- ??????????? alert("琚?璋??ㄥ?闆?斤?");??
- ??????????? ??
- ??????????? }?
- ???????????
- ????????? //娉ㄥ???藉??绌洪??'myNameSpace' ??indow瀵矽薄涓?? ?
- ??????????? window['myNameSpace'] = {}???
- ???????????
- ????????? //??$?芥?版敞????'myNameSpace'?藉??绌洪?翠腑?
- ????????? window['myNameSpace']['$']=$;?
- ???????????
- ??????? })();</SPAN>?
- <span style="font-family: FangSong_GB2312;">//JavaScript搴?妯℃?誇唬???
- ??? (function (){?
- ??????? function $(){?
- ??????????? alert("琚?璋??ㄥ?闆?斤?");??
- ??????????? ??
- ??????????? }?
- ???????????
- ????????? //娉ㄥ???藉??绌洪??'myNameSpace' ??indow瀵矽薄涓?? ?
- ??????????? window['myNameSpace'] = {}???
- ???????????
- ????????? //??$?芥?版敞????'myNameSpace'?藉??绌洪?翠腑?
- ????????? window['myNameSpace']['$']=$;?
- ???????????
- ??????? })();</span>?
//JavaScript搴?妯℃?誇唬?? (function (){ function $(){ alert("琚?璋??ㄥ?闆?斤?"); /*alert()??JavaScript????璇?瑷?涓?绐???indow瀵矽薄??涓?涓?甯哥?ㄦ?規?锛? ?朵富瑕??ㄦ?灏辨???ㄤ???宸卞??涔?浜?涓?瀹????芥?頒互??锛???杩??ц??稿?????浣?锛? ??寮瑰?哄?矽??妗???璇?瑷???骞朵?alert瀵矽??妗???甯哥?ㄤ?涓?浜?瀵圭?ㄦ?風????绀轟俊????*/ } //娉ㄥ???藉??绌洪??'myNameSpace' ??indow瀵矽薄涓? window['myNameSpace'] = {} //??$?芥?版敞????'myNameSpace'?藉??绌洪?翠腑 window['myNameSpace']['$']=$; })();
2.??TML椤甸???寮??ㄨ??宸?S搴?涓????芥?版?瑰?锛?
棣???锛??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ュ??TML??浠舵??棰?涓??癸?渚?濡?
[javascript] view plain copy print ?
[javascript] view plain copy print ?
- <SPAN style="FONT-SIZE: 18px"><SPAN style="FONT-FAMILY: FangSong_GB2312"><title>ICTest</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="IC.js"></script>?
- </SPAN></SPAN>?
- <span style="font-size: 18px;"><span style="font-family: FangSong_GB2312;"><title>ICTest</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="IC.js"></script>?
- </span></span>?
<title>ICTest</title> <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?--> <script language="JavaScript" type="text/javascript" src="IC.js"></script>
?跺??锛???ody灞??т腑璋???S搴?涓????芥?幫?涓ょ??瑰?
??<body 慰nl慰ad="myNameSpace.$()"></body>?? //myNameSpace涓哄??涔????藉??绌洪?達???浠ヨ??ㄨ??宸辨??寤虹??JS搴???浠朵腑?闆?芥?頒?
??lt;body 慰nl慰ad="window.myNameSpace.$()"></body> //?ㄥ?藉??绌洪?村????涓?window涔???瀹??拌???S搴?涓????芥??
涓?.缂?????宸辯??JavaScript搴?(瀹?渚?)
瀹??頒?涓??ㄧ?椤靛??杞芥?跺脊?哄?矽??妗???绠???瀹?渚?锛???瀹?渚???浠????ㄧ?绋?杞?浠?reamweaver 8??
1.??寤鴻??宸辯??JS搴?锛?姝ゅ??藉??绌洪?存???藉??涓?ALY.js??
? 娉ㄦ??锛?澶у?跺??浠ヤ嬌?ㄨ??宸卞??娆㈢????瀛?浣?涓哄?藉??绌洪?寸????瀛?锛?杩??蜂嬌寰??充嬌涓?璧蜂嬌?ㄥ?朵?浜虹?????搴??朵?涓?浼??????鎬?骞叉?扮?????點??
[javascript] view plain copy print ?
[javascript] view plain copy print ?
- <SPAN style="FONT-SIZE: 18px"><SPAN style="FONT-FAMILY: FangSong_GB2312">//ZAJ.js搴?浠g???
- ??? (function (){?
- ??????? function $(){?
- ??????????? alert("AZJ.js搴?琚?璋??ㄥ?闆?斤?");??
- ??????????? }?
- ???????????
- ????????? //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓?? ?
- ??????????? window['AZJ'] = {}???
- ???????????
- ????????? //??$?芥?版敞????'AZJ'?藉??绌洪?翠腑?
- ????????? window['AZJ']['$']=$;?
- ???????????
- ??????? })();</SPAN></SPAN>?
- <span style="font-size: 18px;"><span style="font-family: FangSong_GB2312;">//ZAJ.js搴?浠g???
- ??? (function (){?
- ??????? function $(){?
- ??????????? alert("AZJ.js搴?琚?璋??ㄥ?闆?斤?");??
- ??????????? }?
- ???????????
- ????????? //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓?? ?
- ??????????? window['AZJ'] = {}???
- ???????????
- ????????? //??$?芥?版敞????'AZJ'?藉??绌洪?翠腑?
- ????????? window['AZJ']['$']=$;?
- ???????????
- ??????? })();</span></span>?
//ZAJ.js搴?浠g?? (function (){ function $(){ alert("AZJ.js搴?琚?璋??ㄥ?闆?斤?"); } //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓? window['AZJ'] = {} //??$?芥?版敞????'AZJ'?藉??绌洪?翠腑 window['AZJ']['$']=$; })();
2.??TML椤甸??唬??涓?璋???S搴?锛?杩?琛?楠?璇???????ㄥ??ALY.js涓????芥?般??HTML??浠跺??涓?ALYTest.html
[html] view plain copy print ?
[html] view plain copy print ?
- <SPAN style="FONT-SIZE: 18px"><SPAN style="FONT-FAMILY: FangSong_GB2312"><head>?
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />?
- <title>璋???s搴?娴?璇?</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="AZJ.js"></script>?
- ?
- </head>?
- <body onload="AZJ.$();"> <!--?ㄩ〉?㈠??杞芥?訛?璋???ZJ.js搴?涓????芥?幫?杩???涔???浣跨??lt;body 慰nl慰ad="window.AZJ.$();">-->?
- </body></SPAN></SPAN>?
- <span style="font-size: 18px;"><span style="font-family: FangSong_GB2312;"><head>?
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />?
- <title>璋???s搴?娴?璇?</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="AZJ.js"></script>?
- ?
- </head>?
- <body onload="AZJ.$();"> <!--?ㄩ〉?㈠??杞芥?訛?璋???ZJ.js搴?涓????芥?幫?杩???涔???浣跨??lt;body 慰nl慰ad="window.AZJ.$();">-->?
- </body></span></span>?
3.杩?琛?缃?椤碉?杩?琛?缁???濡???<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>璋???s搴?娴?璇?</title> <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?--> <script language="JavaScript" type="text/javascript" src="AZJ.js"></script> </head> <body 慰nl慰ad="AZJ.$();"> <!--?ㄩ〉?㈠??杞芥?訛?璋???ZJ.js搴?涓????芥?幫?杩???涔???浣跨??lt;body 慰nl慰ad="window.AZJ.$();">--> </body>
??.瀹???JavaScript搴?
杩???涓昏???S搴??垮???芥?頒腑缂???涓や釜甯哥?ㄧ???規?锛?
1.$()?規?
2.getElementsByClassName()?規?
瀹?渚?????js搴?涓???缂???$()?規?
1.寤虹??"AZJ.js"搴?锛?缂???$()?規?,浠g??濡?涓?
[javascript] view plain copy print ?
[javascript] view plain copy print ?
- <SPAN style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 18px">//ZAJ.js搴?浠g???
- ??? (function (){?
- ??????? //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓?? ?
- ??????? window['AZJ'] = {}??
- ?????????
- ??????? //$?芥?扮????浜?getElementByID锛??
- ??????? function $(){?
- ??????????? var elements=new Array();??
- ??????????? //灏?浼??ョ?????拌?琛??????
- ??????????? for(var i=0;i<arguments.length;i++){?
- ??????????????? var element=arguments[i];?
- ??????????????? //?ュ???頒負瀛?绗?覆绫誨??锛?????寰?璇ュ???扮??id?
- ??????????????? if(typeof element=='string'){?
- ??????????????????? element=document.getElementById(element);?
- ??????????????????? }?
- ??????????????? //?ュ???伴?垮害涓?锛??沖??浼???杩??ヤ?涓????幫????存?ヨ????
- ??????????????? if(arguments.length==1){?
- ??????????????????? return element;?
- ??????????????????? }?
- ??????????????? //?ユ??澶?涓????頒???杩??ワ???灏?澶????????煎????lements?扮?涓??
- ??????????????? elements.push(element);?
- ??????????????? }?
- ??????????????? //杩???澶??????????奧?
- ??????????????? return elements;?
- ??????????? }?
- ???????????
- ???????????
- ????????? //????寤虹???芥??娉ㄥ????'window.AZJ'?藉??绌洪?翠腑?
- ????????? window['AZJ']['$']=$;?
- ???????????
- ??????? })();</SPAN>?
- <span style="font-family: FangSong_GB2312; font-size: 18px;">//ZAJ.js搴?浠g???
- ??? (function (){?
- ??????? //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓?? ?
- ??????? window['AZJ'] = {}??
- ?????????
- ??????? //$?芥?扮????浜?getElementByID锛??
- ??????? function $(){?
- ??????????? var elements=new Array();??
- ??????????? //灏?浼??ョ?????拌?琛??????
- ??????????? for(var i=0;i<arguments.length;i++){?
- ??????????????? var element=arguments[i];?
- ??????????????? //?ュ???頒負瀛?绗?覆绫誨??锛?????寰?璇ュ???扮??id?
- ??????????????? if(typeof element=='string'){?
- ??????????????????? element=document.getElementById(element);?
- ??????????????????? }?
- ??????????????? //?ュ???伴?垮害涓?锛??沖??浼???杩??ヤ?涓????幫????存?ヨ????
- ??????????????? if(arguments.length==1){?
- ??????????????????? return element;?
- ??????????????????? }?
- ??????????????? //?ユ??澶?涓????頒???杩??ワ???灏?澶????????煎????lements?扮?涓??
- ??????????????? elements.push(element);?
- ??????????????? }?
- ??????????????? //杩???澶??????????奧?
- ??????????????? return elements;?
- ??????????? }?
- ???????????
- ???????????
- ????????? //????寤虹???芥??娉ㄥ????'window.AZJ'?藉??绌洪?翠腑?
- ????????? window['AZJ']['$']=$;?
- ???????????
- ??????? })();</span>?
//ZAJ.js搴?浠g?? (function (){ //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓? window['AZJ'] = {} //$?芥?扮????浜?getElementByID锛? function $(){ var elements=new Array(); //灏?浼??ョ?????拌?琛????? for(var i=0;i<arguments.length;i++){ var element=arguments[i]; //?ュ???頒負瀛?绗?覆绫誨??锛?????寰?璇ュ???扮??id if(typeof element=='string'){ element=document.getElementById(element); } //?ュ???伴?垮害涓?锛??沖??浼???杩??ヤ?涓????幫????存?ヨ??? if(arguments.length==1){ return element; } //?ユ??澶?涓????頒???杩??ワ???灏?澶????????煎????lements?扮?涓? elements.push(element); } //杩???澶??????????? return elements; } //????寤虹???芥??娉ㄥ????'window.AZJ'?藉??绌洪?翠腑 window['AZJ']['$']=$; })();
2.??TML椤甸?㈣?琛?娴?璇?
褰?浠????㈠??浼???涓?涓????版?訛?浠g??璁捐??
[html] view plain copy print ?
[html] view plain copy print ?
- <SPAN style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 18px"><title>璋???s搴?娴?璇?</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="AZJ.js"></script>?
- <script language="JavaScript" type="text/javascript" >?
- ??? function testClick(){?
- ??????? var testInput=AZJ.$("testID");?
- ??????? alert(testInput.value);?
- ??? }?
- </script>?
- </head>?
- <body >?
- <input type="text" value="AZJtest" id="testID"/>?
- <input type="button" value="Click Me" onclick="testClick()"/>?
- </body></SPAN>?
- <span style="font-family: FangSong_GB2312; font-size: 18px;"><title>璋???s搴?娴?璇?</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="AZJ.js"></script>?
- <script language="JavaScript" type="text/javascript" >?
- ??? function testClick(){?
- ??????? var testInput=AZJ.$("testID");?
- ??????? alert(testInput.value);?
- ??? }?
- </script>?
- </head>?
- <body >?
- <input type="text" value="AZJtest" id="testID"/>?
- <input type="button" value="Click Me" onclick="testClick()"/>?
- </body></span>?
杩?琛?缁???涓猴??瑰??Click Me"????锛?寮瑰?虹?椤墊???锛?AZJtest<title>璋???s搴?娴?璇?</title> <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?--> <script language="JavaScript" type="text/javascript" src="AZJ.js"></script> <script language="JavaScript" type="text/javascript" > function testClick(){ var testInput=AZJ.$("testID"); alert(testInput.value); } </script> </head> <body > <input type="text" value="AZJtest" id="testID"/> <input type="button" value="Click Me" 慰nclick="testClick()"/> </body>
褰?浠????????涓や釜???版?訛?浠g??璁捐??
[html] view plain copy print ?
[html] view plain copy print ?
- <SPAN style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 18px"><title>璋???s搴?娴?璇?</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="AZJ.js"></script>?
- <script language="JavaScript" type="text/javascript" >?
- ??? function testClick(){?
- ??????? var testInput=AZJ.$("testID","testID2");?
- ??????? //?變?杩?????涓や釜???幫???浠ョ??or璇??ラ????涓や釜???幫??????劇ず?烘?ヂ?
- ??????? for(var i=0;i<testInput.length;i++){?
- ??????? alert(testInput[i].value);?
- ??????? }?
- ?????????
- ??? }?
- </script>?
- </head>?
- <body >?
- <input type="text" value="AZJtest" id="testID"/>?
- <input type="text" value="AZJtest2" id="testID2"/>?
- <input type="button" value="Click Me" onclick="testClick()"/>?
- </body></SPAN>?
- <span style="font-family: FangSong_GB2312; font-size: 18px;"><title>璋???s搴?娴?璇?</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="AZJ.js"></script>?
- <script language="JavaScript" type="text/javascript" >?
- ??? function testClick(){?
- ??????? var testInput=AZJ.$("testID","testID2");?
- ??????? //?變?杩?????涓や釜???幫???浠ョ??or璇??ラ????涓や釜???幫??????劇ず?烘?ヂ?
- ??????? for(var i=0;i<testInput.length;i++){?
- ??????? alert(testInput[i].value);?
- ??????? }?
- ?????????
- ??? }?
- </script>?
- </head>?
- <body >?
- <input type="text" value="AZJtest" id="testID"/>?
- <input type="text" value="AZJtest2" id="testID2"/>?
- <input type="button" value="Click Me" onclick="testClick()"/>?
- </body></span>?
杩?琛?缁???锛?????Click Me"????,??寮瑰??ZJtest锛???寮瑰??ZJtest2<title>璋???s搴?娴?璇?</title> <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?--> <script language="JavaScript" type="text/javascript" src="AZJ.js"></script> <script language="JavaScript" type="text/javascript" > function testClick(){ var testInput=AZJ.$("testID","testID2"); //?變?杩?????涓や釜???幫???浠ョ??or璇??ラ????涓や釜???幫??????劇ず?烘?? for(var i=0;i<testInput.length;i++){ alert(testInput[i].value); } } </script> </head> <body > <input type="text" value="AZJtest" id="testID"/> <input type="text" value="AZJtest2" id="testID2"/> <input type="button" value="Click Me" 慰nclick="testClick()"/> </body>
瀹?渚?娣卞?ワ?缂???getElementByClassName()?規?
1.??AZJ.js"搴?涓?缂???getElementByClassName()?規?锛?浠g??璁捐?″?涓?
[javascript] view plain copy print ?
[javascript] view plain copy print ?
- <SPAN style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 18px">//ZAJ.js搴?浠g???
- ??? (function (){?
- ??????? //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓?? ?
- ??????? window['AZJ'] = {}??
- ?????????
- ????????? //getElementsByClassName????涓や釜???幫?绫誨??锛???绛懼???
- ????????? function getElementsByClassName(className,tag){?
- ????????????? //瀵?ag杩?琛?杩?婊わ????烘????瀵矽薄锛?濡????烘????input绫誨??瀵矽薄???
- ????????????? var allTags=document.getElementsByTagName(tag);?
- ????????????? var matchingElements=new Array();?
- ???????????????
- ????????????? //姝e??琛ㄨ揪寮??
- ????????????? className = className.replace(/\-/g,"\\-");?
- ????????????? var regex = new RegExp("(^|\\s)" +className+ "(\\s|$)");?
- ???????????????
- ????????????? var element;?
- ???????????????
- ????????????? //灏????虹??tag瀵矽薄瀛??ユ?扮?涓????
- ????????????? for(var i=0;i<allTags.length;i++){?
- ????????????????? element =allTags[i];?
- ????????????????? if(regex.test(element.className)){?
- ????????????????????? matchingElements.push(element);?
- ????????????????????? }?
- ????????????????? }?
- ????????????? return matchingElements;?
- ????????????? }?
- ????????? //????寤虹???芥??etElementsByClassName娉ㄥ????'window.AZJ'?藉??绌洪?翠腑?
- ????????? window['AZJ']['getElementsByClassName']=getElementsByClassName;?
- ??????? })();</SPAN>?
- <span style="font-family: FangSong_GB2312; font-size: 18px;">//ZAJ.js搴?浠g???
- ??? (function (){?
- ??????? //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓?? ?
- ??????? window['AZJ'] = {}??
- ?????????
- ????????? //getElementsByClassName????涓や釜???幫?绫誨??锛???绛懼???
- ????????? function getElementsByClassName(className,tag){?
- ????????????? //瀵?ag杩?琛?杩?婊わ????烘????瀵矽薄锛?濡????烘????input绫誨??瀵矽薄???
- ????????????? var allTags=document.getElementsByTagName(tag);?
- ????????????? var matchingElements=new Array();?
- ???????????????
- ????????????? //姝e??琛ㄨ揪寮??
- ????????????? className = className.replace(/\-/g,"\\-");?
- ????????????? var regex = new RegExp("(^|\\s)" +className+ "(\\s|$)");?
- ???????????????
- ????????????? var element;?
- ???????????????
- ????????????? //灏????虹??tag瀵矽薄瀛??ユ?扮?涓????
- ????????????? for(var i=0;i<allTags.length;i++){?
- ????????????????? element =allTags[i];?
- ????????????????? if(regex.test(element.className)){?
- ????????????????????? matchingElements.push(element);?
- ????????????????????? }?
- ????????????????? }?
- ????????????? return matchingElements;?
- ????????????? }?
- ????????? //????寤虹???芥??etElementsByClassName娉ㄥ????'window.AZJ'?藉??绌洪?翠腑?
- ????????? window['AZJ']['getElementsByClassName']=getElementsByClassName;?
- ??????? })();</span>?
//ZAJ.js搴?浠g?? (function (){ //娉ㄥ???藉??绌洪??'AZJ' ??indow瀵矽薄涓? window['AZJ'] = {} //getElementsByClassName????涓や釜???幫?绫誨??锛???绛懼?? function getElementsByClassName(className,tag){ //瀵?ag杩?琛?杩?婊わ????烘????瀵矽薄锛?濡????烘????input绫誨??瀵矽薄?? var allTags=document.getElementsByTagName(tag); var matchingElements=new Array(); //姝e??琛ㄨ揪寮? className = className.replace(/\-/g,"\\-"); var regex = new RegExp("(^|\\s)" +className+ "(\\s|$)"); var element; //灏????虹??tag瀵矽薄瀛??ユ?扮?涓??? for(var i=0;i<allTags.length;i++){ element =allTags[i]; if(regex.test(element.className)){ matchingElements.push(element); } } return matchingElements; } //????寤虹???芥??etElementsByClassName娉ㄥ????'window.AZJ'?藉??绌洪?翠腑 window['AZJ']['getElementsByClassName']=getElementsByClassName; })();
2.??TML椤甸?㈣?琛?娴?璇?
娴?璇??瑰???涓??????涓や釜???扮???瑰?锛?浠g??璁捐?″?涓?
[html] view plain copy print ?
[html] view plain copy print ?
- <SPAN style="FONT-FAMILY: FangSong_GB2312; FONT-SIZE: 18px"><title>璋???s搴?娴?璇?</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="AZJ.js"></script>?
- <script language="JavaScript" type="text/javascript" >?
- ??? function testClick(){?
- ??????? var testInput=AZJ.getElementsByClassName("testme","input");?
- ??????? //?變?杩?????涓や釜???幫???浠ョ??or璇??ラ????涓や釜???幫??????劇ず?烘?ヂ?
- ??????? for(var i=0;i<testInput.length;i++){?
- ??????? alert(testInput[i].value);?
- ??????? }?
- ?????????
- ??? }?
- </script>?
- </head>?
- <body >?
- <input type="text" value="AZJtest" class ="testme" id="testID"/>?
- <input type="text" value="AZJtest2" class="testme" id="testID2"/>?
- <input type="button" value="Click Me" onclick="testClick()"/>?
- </body></SPAN>?
- <span style="font-family: FangSong_GB2312; font-size: 18px;"><title>璋???s搴?娴?璇?</title>?
- <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?-->?
- <script language="JavaScript" type="text/javascript" src="AZJ.js"></script>?
- <script language="JavaScript" type="text/javascript" >?
- ??? function testClick(){?
- ??????? var testInput=AZJ.getElementsByClassName("testme","input");?
- ??????? //?變?杩?????涓や釜???幫???浠ョ??or璇??ラ????涓や釜???幫??????劇ず?烘?ヂ?
- ??????? for(var i=0;i<testInput.length;i++){?
- ??????? alert(testInput[i].value);?
- ??????? }?
- ?????????
- ??? }?
- </script>?
- </head>?
- <body >?
- <input type="text" value="AZJtest" class ="testme" id="testID"/>?
- <input type="text" value="AZJtest2" class="testme" id="testID2"/>?
- <input type="button" value="Click Me" onclick="testClick()"/>?
- </body></span>?
<title>璋???s搴?娴?璇?</title> <!--姝ゅ???杩??ц?"???モ??HTML??????瀵矽薄??????"锛???绱???宸辮????ュ?版??TML椤電??js搴???浠舵???ユ?や?缃?--> <script language="JavaScript" type="text/javascript" src="AZJ.js"></script> <script language="JavaScript" type="text/javascript" > function testClick(){ var testInput=AZJ.getElementsByClassName("testme","input"); //?變?杩?????涓や釜???幫???浠ョ??or璇??ラ????涓や釜???幫??????劇ず?烘?? for(var i=0;i<testInput.length;i++){ alert(testInput[i].value); } } </script> </head> <body > <input type="text" value="AZJtest" class ="testme" id="testID"/> <input type="text" value="AZJtest2" class="testme" id="testID2"/> <input type="button" value="Click Me" 慰nclick="testClick()"/> </body>
杩?琛?缁???锛???涓?杩版?規?涓?浼???涓や釜???扮?????點??
??绔????拌???锛??鎬俊?ㄤ?浼?缂???绠?????js搴???浠朵??э?缂???js搴???浠舵??涓???寰?绠?????