getElementById()ã§nameå±æ§ãæ¤ç´¢ãããï¼
getElementById()ã§nameå±æ§ãæ¤ç´¢ãã¦ã¨ã¬ã¡ã³ããåå¾ã§ããã¨ãã話ãèããã
ããã絶対ã«æ¨å¥¨ããã¦ãã使ãæ¹ã§ã¯ãªãã ããã
ããããIDã¯ãã¼ã¸å
ã§ã¦ãã¼ã¯ã ããgetElementById()ã¯ã¨ã¬ã¡ã³ããè¿ãã¦ã
è¤æ°è¨å®ã§ããnameå±æ§ç¨ã«Arrayãªãã¸ã§ã¯ãElementãªãã¸ã§ã¯ãï¼NodeListãªãã¸ã§ã¯ãï¼
ã§è¿ã£ã¦ãããgetElementsByName()ãããã®ã ããã
ã§ããå®éã§ããã£ã¦èãããã
ã ããã調ã¹ã¦ã¿ãã
ã»ãã¨ã«ã¨ããã®ãï¼
ãµã³ãã«ã®HTML + JavaScriptãç¨æããã
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3c.org/1999/xhtml"> <head> <meta http-equiv="Contet-Type" content="text/html; charaset=TF-8"/> <title></title> <script type="text/javascript"> window.onload = function(){ alert(document.getElementById("txt1").value) } </script> </head> <body> <input type="text" name="txt1" value="name"></input> </body> </html>
çµæ
ã§ãçµæ
OS | ãã©ã¦ã¶ | ã¹ã¯ãªããå®è¡çµæ |
---|---|---|
WinXP | IE7 | nameã¨è¡¨ç¤ºããã |
WinXP | IE6 | nameã¨è¡¨ç¤ºããã |
WinXP | FireFox2 | ã¹ã¯ãªããã¨ã©ã¼ |
MacOS10.4 | Safari3.1 | ã¹ã¯ãªããã¨ã©ã¼ |
IEã¯åå¾å¯è½ã®ããã ããã
ã§ã¯ãåãååã®IDã¨nameããã£ããï¼
å ã»ã©ã®ã½ã¼ã¹ã«åãIDã追å ãã¦è¦ã
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3c.org/1999/xhtml"> <head> <meta http-equiv="Contet-Type" content="text/html; charaset=TF-8"/> <title></title> <script type="text/javascript"> window.onload = function(){ alert(document.getElementById("txt1").value) } </script> </head> <body> <input type="text" name="txt1" value="name"></input> <input type="text" id="txt1" value="id"></input> </body> </html>
åãIDãnameããå¾ã«ãã¦ãã®ã«ãããããããã½ã
ããã¦çµæ
OS | ãã©ã¦ã¶ | ã¹ã¯ãªããå®è¡çµæ |
---|---|---|
WinXP | IE7 | nameã¨è¡¨ç¤ºãããï¼ãï¼ï¼ |
WinXP | IE6 | nameã¨è¡¨ç¤ºãããï¼ãï¼ï¼ |
WinXP | FireFox2 | idã¨è¡¨ç¤ºãããï¼æ£å¸¸ï¼ |
MacOS10.4 | Safari3.1 | idã¨è¡¨ç¤ºãããï¼æ£å¸¸ï¼ |
IEã¯idã¨nameã®ä¸¡æ¹ãã¿ã¦ãã£ã½ãã
ããã¦ããã¡ã®æªããã¨ã«æåã«è¦ã¤ããã®ãã¨ã£ã¦ãã¦ãã£ã½ãã
ã»ãã¨ã«æåãã¨ã£ã¦ãã®ãï¼
idã¨nameãã²ã£ããè¿ãã¦ç¢ºèªãã¦ã¿ãã
ããã«çµæ
OS | ãã©ã¦ã¶ | ã¹ã¯ãªããå®è¡çµæ |
---|---|---|
WinXP | IE7 | idã¨è¡¨ç¤ºãããï¼æ£å¸¸ï¼ã |
WinXP | IE6 | idã¨è¡¨ç¤ºãããï¼æ£å¸¸ï¼ã |
WinXP | FireFox2 | idã¨è¡¨ç¤ºãããï¼æ£å¸¸ï¼ |
MacOS10.4 | Safari3.1 | idã¨è¡¨ç¤ºãããï¼æ£å¸¸ï¼ |
ãã£ã±ãæåãã¨ã£ã¦ãããã
ã¾ã¨ããã¨
IEã¯getElementById()ã¯idã¨nameå±æ§ä¸¡æ¹ã対象ã«æ¤ç´¢ãã¦æåã«è¦ã¤ãã£ããã®ã
åã£ã¦ããããã ã
æ®éã¯ãããªããã¨ã ãã©ãidã¨nameã¯çµ¶å¯¾ã«åãååã¯ããã¨ãã
nameå±æ§ã§æ¤ç´¢ããã¨ãã¯getElementsByName()ã使ãã
åãæ±ãã«ã¯åäºåã«æ°ãã¤ããã