HTML DOM getElementsByName() ·½·¨

¶¨ÒåºÍÓ÷¨

getElementsByName() ·½·¨¿É·µ»Ø´øÓÐÖ¸¶¨Ãû³ÆµÄ¶ÔÏóµÄ¼¯ºÏ¡£

Óï·¨

document.getElementsByName(name)

¸Ã·½·¨Óë getElementById() ·½·¨ÏàËÆ£¬µ«ÊÇËü²éÑ¯ÔªËØµÄ name ÊôÐÔ£¬¶ø²»ÊÇ id ÊôÐÔ¡£

ÁíÍ⣬ÒòΪһ¸öÎĵµÖÐµÄ name ÊôÐÔ¿ÉÄܲ»Î¨Ò»£¨Èç HTML ±íµ¥Öеĵ¥Ñ¡°´Å¥Í¨³£¾ßÓÐÏàͬµÄ name ÊôÐÔ£©£¬ËùÓÐ getElementsByName() ·½·¨·µ»ØµÄÊÇÔªËØµÄÊý×飬¶ø²»ÊÇÒ»¸öÔªËØ¡£

ʵÀý

<html>
<head>
<script type="text/javascript">
function getElements()
  {
  var x=document.getElementsByName("myInput");
  alert(x.length);
  }
</script>
</head>
<body>

<input name="myInput" type="text" size="20" /><br />
<input name="myInput" type="text" size="20" /><br />
<input name="myInput" type="text" size="20" /><br />
<br />
<input type="button" onclick="getElements()"
value="How many elements named 'myInput'?" />

</body>
</html>
VUE