.html代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>表单</title>
<script type="text/javascript">
function test(){
alert(document.myForm.method);
alert(document.forms[0].method);
document.forms[0].submit();
alert(document.myForm.userName.value);
alert(document.myForm.elements[1].value);
var name = document.forms[0].elements[0].value;//得到用户名
var pwd = document.forms[0].elements[1].value;//得到密码
if(name == "admin" && pwd == "888"){//判断用户名密码是否满足
document.myForm.submit();
}else{
alert("输入错误");
}
}
</script>
</head>
<body >
<form name="myForm">
<label>用户名:</label><input type="text" name="userName" />
<label>密码:</label><input type="password" name="pwd"/>
<input type="button" value="确定" οnclick="test()"/>
<input type="reset" value="取消"/>
</form>
</body>
</html>
alert(document.myForm.method);结果为get
alert(document.forms[0].method);结果为get
<pre name="code" class="javascript"><pre name="code" class="javascript">document.forms[0].submit();//submit方法,点击时所有东西清空,页面刷新。
alert(document.myForm.userName.value);//获得用户名
alert(document.myForm.elements[1].value);//获得密码