获取form表单元素值的4种方式

<html>
<head>
<title></title>
<script type="text/javascript">
function checkForm(){
var name=document.form1.number.value; //or form1.number.value
var name=document.forms[0].number.value;
var name=document.forms[0]['number'].value;
var name=document.form1['number'].value //or form1['number'].value
alert(name);

}
</script>
</head>
<body>
<form name="form1" method="post" action="">
网元名称:<input type="text" name="number" size="20">
<br>
<input type="submit" value="提交" onClick="checkForm()">
</form>
</body>
</html>

原文地址:https://www.cnblogs.com/huhongda/p/4178031.html