HTML部分
<form> <input type="text" value="请输入用户名" id=”number”><br /> <input type=" button" value="提交" οnclick="checkForm()"> </form> JS部分
方法1:
<script> funciton checkForm(){ var obj=document.getElementById("number").value; alert(obj) } </script>
方法2:
<form id ="form1" name=”form1”> 代号:<input type="text" name="a" value="1"><br> 代号:<input type="text" name="a" value="2"><br> 代号:<input type="text" name="a" value="3"><br> <input type="submit" value="提交"> </form> </body> <script type="text/javascript"> document.getElementById('form1').onsubmit=function(){ // div.οnclick=function(){} var as=document.getElementsByName('a'); //数组 for(i=0; i<as.length;i++){ alert(as[i].value); } } </script>
方法3:
<script> funciton checkForm(){ var obj=document.form1.number.value; var obj=document.forms[0].number.value;// var obj=document.forms[0]['number'].value; var obj=document.form1['number'].value; } </script>
DOM寻址方法:
getElementById
getElementsByName
getElementsByTagName
getElementsByClassName