`
ilovejsj
  • 浏览: 207449 次
  • 性别: 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
分享到:
评论

相关推荐

    form.submit()不能提交表单的原因分析

    2. **避免与API重名**:在定义ID、类名或变量名时,最好避免与JavaScript或DOM API中的保留关键字和属性名称相同,以减少潜在问题。 总结: 在进行Web开发时,遵循良好的编程和命名规范至关重要。对于表单提交,...

    php+ajax实现带进度条的上传图片功能【附demo源码下载】

    document.getElementById('progressBar').value = progress; }; xhr.onloadstart = function() { document.getElementById('progressBar').value = 0; }; xhr.onloadend = function() { document....

    FCKeditor的几点修改小结

    varddl=oEditor.parent.document.Form1.ddlPicUrl; varopt=oEditor.parent.document.createElement("OPTION") opt.text=fileName; opt.value=fileUrl ddl.options.add(opt); ``` - 其中,`oEditor`是对网页...

    php html5 文件上传

    document.getElementById('progressBar').value = Math.round(percent); }, false); xhr.onload = function() { alert(xhr.responseText); }; xhr.send(formData); } ``` 在这个例子中,当用户点击“上传...

    结合SpringMVC上传文件

    &lt;property name="maxUploadSize" value="10485760"/&gt; &lt;!-- 10MB --&gt; ``` 接下来,我们创建一个Controller来处理文件上传请求。在Controller类中,定义一个方法,使用`@RequestParam("file") MultipartFile file`...

    php+ajax+h5实现图片上传功能

    formData.append("myfile", document.getElementById("file1").files[0]); $.ajax({ url: "/Home/index/fileupsend", type: "POST", data: formData, contentType: false, processData: false, success: ...

Global site tag (gtag.js) - Google Analytics