js的onsubmit和onreset的使用和基本操作
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
//测试submit() reset()
function test(){
var form1=document.form1;
// form1.submit(); //功能同 input submit
form1.reset();//功能同 input reset
}
function test01(){
alert("即将要提交了!");
return false;
}
function test02(){
alert("即将要重置了!");
}
//表单对象.form 返回该表单对象所在的form 对象
function test03(){
var uname=document.getElementById("uname");
alert(uname.form.nodeName);//FORM
alert(uname.form.nodeType);//text
// 表单域对象.type 返回 表单域对象的类型
alert(uname.type);//1
}
function testFocus(){
var uname=document.form1.uname;
uname.focus();
}
</script>
</head>
<body>
<form name="form1" id="formId" action="test.html" method="get" οnsubmit="return test01()" οnreset="test02()">
用户名:<input name="uname" id="uname" /><br/>
密码:<input type="password" name="pwd"/><br/>
<!--<input type="button" value="提交" οnclick="test()"/>-->
<input type="submit" value="提交" />
<input type="reset" value="重置" />
</form>
<input type="button" value="searchForm" οnclick="test03()" />
<input type="button" value="testFocus" οnclick="testFocus()" />
</body>
</html>