`
ilovejsj
  • 浏览: 203565 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

document.form1.*.value重名报错

 
阅读更多
环境IE8
<html>
<head>
<title>JS</title>
<script type="text/javascript">
function test(){
alert(document.getElementsByName("fpdm")[0].value)
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="fpdm">
<input type="text" name="fpdm">
</form>
<input type="button" onclick="test()" value="Click">
</body>
</html>
(1)
function test(){
alert(document.form1.fpdm.value)
}
报错:undefined;
同一个表单多个同名的就报错,不会自动取第一个对象。
(2)
function test(){
alert(document.getElementsByName("fpdm")[0].value)
}
ok
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics