赞
踩
12:37:59 <html> <head> </head> <body> <form name="Form1" οnsubmit="check();"> <input type="text" name="loginName" id="loginName"><br> <input type="password" name="loginPass" id="loginPass"></br> <input type="submit" value="check"> </form> </body> </html> <mce:script type="text/javascript"><!-- function check(){ //方法1 alert("方法1:"+Form1.loginName.value+" "+Form1.loginPass.value); //方法2 var name = document.all("loginName").value; var pass = document.all("loginPass").value; alert("方法2:"+name+" "+pass); //方法3 var name2 = document.getElementById("loginName").value; var pass2 =document.getElementById("loginPass").value; alert("方法3:"+name2+" "+pass2); //方法4 var name3 = document.getElementsByTagName("input").item(0).value; alert(name3); //方法5 //var name4 = document.getElementsByTagName("input")[0].name; var name4 = document.getElementsByTagName("input")[0].value; alert("方法5:"+name4); //方法6 with(Form1){ //用此方法6如果声明var loginName = loginName.value将取不到值 alert("方法6:"+loginName.value+" "+loginPass.value); } } // --></mce:script>