Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

javascriptÖ®getAttribute()·½·¨

getAttribute()·½·¨
 ¡ñÒ»·ÝÎĵµ¾ÍÊÇÒ»¿Ã½ÚµãÊ÷¡£
  ¡ñ½Úµã·ÖΪ²»Í¬µÄÀàÐÍ£ºÔªËؽڵ㡢ÊôÐÔ½ÚµãºÍÎı¾½ÚµãµÈ¡£
  ¡ñgetElementById()·½·¨½«·µ»ØÒ»¸ö¶ÔÏ󣬸öÔÏó¶ÔÓ¦×ÅÎĵµÀïµÄÒ»¸öÌض¨µÄÔªËؽڵ㡣
  ¡ñgetElementsByTagName()·½·¨½«·µ»ØÒ»¸ö¶ÔÏóÊý×飬ËüÃÇ·Ö±ð¶ÔÓ¦×ÅÎĵµÀïµÄÒ»¸öÌض¨µÄÔªËؽڵ㡣
  ¡ñÕâЩ½ÚµãÖеÄÿ¸ö¶¼ÊÇÒ»¸ö¶ÔÏó¡£
½ÓÏÂÀ´£¬ÎÒÃǽ«Ïò´ó¼Ò½éÉܼ¸¸öÓëÕâЩ¶ÔÏóÏà¹ØÁªµÄÊôÐԺͷ½·¨¡£
3.4.1¡¡getAttribute()·½·¨
ÖÁ´Ë£¬ÎÒÃÇÒѾ­Ïò´ó¼Ò½éÉÜÁËÁ½ÖÖ¼ìË÷Ìض¨ÔªËؽڵãµÄ°ì·¨£ºÒ»ÖÖÊÇʹÓÃgetElementById()·½·¨£¬ÁíÒ»ÖÖÊÇʹÓÃgetElementsByTagName()·½·¨¡£ÔÚÕÒµ½ÄǸöÔªËغó£¬ÎÒÃǾͿÉÒÔÀûÓÃgetAttribute()·½·¨°ÑËüµÄ¸÷ÖÖÊôÐÔµÄÖµ²éѯ³öÀ´¡£
getAttribute()·½·¨ÊÇÒ»¸öº¯Êý¡£ËüÖ»ÓÐÒ»¸ö²ÎÊý——Äã´òËã²éѯµÄÊôÐÔµÄÃû×Ö£º
object.getAttribute(attribute)
²»¹ý£¬getAttribute()·½·¨²»ÄÜͨ¹ýdocument¶ÔÏóµ÷Óã¬ÕâÓëÎÒÃÇ´ËÇ°½éÉܹýµÄÆäËû·½·¨²»Í¬¡£ÎÒÃÇÖ»ÄÜͨ¹ýÒ»¸öÔªËؽڵã¶ÔÏóµ÷ÓÃËü¡£
ÀýÈ磬Äã¿ÉÒÔ°ÑËüÓëgetElementsByTagName()·½·¨½áºÏÆðÀ´£¬È¥²éѯÿ¸ö<p>ÔªËصÄtitleÊôÐÔ£¬ÈçÏÂËùʾ£º
var text=document.getElementsByTagName("p")
for (var i=0;i<text.length;i++)
{
alert(text[i].getAttribute("title"));
}
Èç¹û°ÑÉÏÃæÕâ¶Î´úÂë²åÈ뵽ǰÃæ¸ø³öµÄ“¹ºÎïÇåµ¥”ʾÀýÎĵµµÄĩ⣬²¢ÔÚWebä¯ÀÀÆ÷ÀïÖØмÓÔØÕâ¸öÒ³Ã棬ÆÁÄ»ÉϽ«µ¯³öÒ»¸öÏÔʾ×ÅÎı¾ÏûÏ¢“a gentle reminder”µÄalter¶Ô»°¿ò¡£
ÔÚ“¹ºÎïÇåµ¥”ÎĵµÀïÖ»ÓÐÒ»¸ö´øÓÐtitleÊôÐÔµÄ<p>ÔªËØ¡£¼ÙÈçÕâ·ÝÎĵµ»¹ÓÐÒ»¸ö»ò¸ü¶à¸ö²»´øtitleÊôÐÔµÄ<p>ÔªËØ£¬ÔòÏàÓ¦µÄgetAttribute("title")µ÷Óý«·µ»Ønull¡£nullÊÇJavaScriptÓïÑÔÖеĿÕÖµ£¬Æ京ÒåÊÇ“Äã˵µÄÕâ¸ö¶«Î÷²»´æÔÚ”¡£Èç¹ûÄãÃÇÏëÇ××ÔÑéÖ¤Ò»ÏÂÕâ¼þÊ£¬ÇëÏÈ°ÑÏÂÃæÕâ¶ÎÎı¾²åÈëµ½“¹ºÎïÇåµ¥”ÎĵµÖеÄÏÖÓÐÎı¾¶ÎÂäÖ®ºó£º
<p>This is just test</p>
È»ºóÖØмÓÔØÕâ¸öÒ³Ãæ¡£ÕâÒ»´Î£¬ÄãÃǽ«¿´µ½Á½¸öalter¶Ô»°¿ò£¬¶øµÚ¶þ¸ö¶Ô»°¿ò½«ÊÇһƬ¿Õ°×»òÕßÊÇÖ»ÏÔʾ×ŵ¥´Ê“null”——¾ßÌåÇé¿öҪȡ¾öÓÚÄãµÄWebä¯ÀÀÆ÷½«ÈçºÎÏÔʾnullÖµ¡£
¿ÉÒÔÐÞ¸ÄÎÒÃǵĽű¾£¬ÈÃËüÖ»ÔÚtitleÊôÐÔ´æÔÚʱ²Åµ¯³öÒ»ÌõÏûÏ¢¡£ÎÒÃǽ«Ôö¼ÓÒ»ÌõifÓï¾äÀ´¼ì²


Ïà¹ØÎĵµ£º

7 JavaScript Differences Between Firefox & IE

Although the days of long and tedious code branches to target specific browsers in JavaScript are over, once in a while it's still necessary to do some simple code branching and object detection to ensure that a certain piece of code is working properly on a user's machine. 
In this article, I ......

JavaScript KeyCodeÊý×Ö¼üÅ̶ÔÓ¦

keycode    8 = BackSpace BackSpace
keycode    9 = Tab Tab
keycode   12 = Clear
keycode   13 = Enter
keycode   16 = Shift_L
keycode   17 = Control_L
keycode   18 = Alt_L
keycode   19 = Pause
keyc ......

javascriptÖÐFORM±íµ¥µÄsubmit()·½·¨¾­Ñé½Ìѵ

@author    songfeng     
       ÒòΪJSÄÚ¶ÔÏóµÄ·½·¨Êµ¼ÊÉÏÊÇ´æ´¢Óï¾äµÄÒ»¸öÀàËÆÓÚÖ¸ÕëµÄ¶«Î÷. ÆäÖ¸ÏòÁËÄÚ´æµÄÒ»¸öλÖÃ, Ò²¾ÍÊÇÆ亯ÊýµÄλÖÃ,µ±È»Ò²¿ÉÒÔÈÃÆäÖ¸ÏòÒ»¸ö±äÁ¿Öµ.
       var foo = new Object();
&nbs ......

Javascript¼ì²âMedia Player°æ±¾£¡

      ÔÚweb¿ª·¢¹ý³ÌÖУ¬¾­³£»á³öÏÖÒòΪ¿Í»§¶ËµÄijЩÈí¼þ°æ±¾ÎÊÌ⣬¶øµ¼ÖÂÖÖÖÖÎÊÌâ¡£ÕâÀ´Ìì¾ÍÒòΪMedia Player°æ±¾µÄÎÊÌ⣬Òý·¢ÁËÒ»¸ö²»´ó²»Ð¡µÄÎÊÌâ¡£ÔÚµ÷ÓÃMedia Player²¥·ÅÊÓƵµÄʱºò£¬Media Player9¾¹È»²¥·Å²»ÁË ...  ...
 
²»¶à˵ÁË£¬»¹ÊÇÌù´úÂë°É£¡
 
<html xmlns="h ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ