我正在做一个简单的 Javascript 表单验证,但无法访问表单中的元素。似乎命令:
document.forms["myForm"]["un"].value;
适用于资源管理器,但不适用于 Firefox。我正在处理的表格是:
<form name = "myForm" onsubmit="check()" method="POST">
User Name:<br><input type="text" name = "un"><br/>
Password:<br><input type="password" name = "pw"><br/>
Confirm Password:<br><input type="password" name = "cpw"><br/>
Email:<br><input type = "text" name = "em"><br/>
<input type = "submit" id = "sub" value="submit">
让 js 验证为:
<script type = "text/javascript">
var user = document.forms["myForm"]["un"].value;
alert(user);
</script>