onsubmit:事件 当提交表单的时候触发
submit()方法 提交表单
<!DOCTYPE html>
<html>
<head>
<meta charset="{CHARSET}">
<title></title>
<script>
window.onload = function(){
var oForm = document.getElementById('form1');
oForm.onsubmit = function(){
if(this.text1.value == ''){
alert('请输入内容');
return false;
}
}
setTimeout(function(){
oForm.submit();
},1000);
}
</script>
</head>
<body>
<form id="form1" action="http://baidu.com">
<input type="text" name="text1" value="" />
<input type="submit" value="提交" name="dosubmit" />
</form>
</body>
</html>
onreset:事件 当提交表单重置的时候触发
<!DOCTYPE html>
<html>
<head>
<meta charset="{CHARSET}">
<title></title>
<script>
window.onload = function(){
var oForm = document.getElementById('form1');
oForm.onreset = function(){
confirm('你确定要重置?');
}
}
</script>
</head>
<body>
<form id="form1" action="http://baidu.com">
<input type="text" name="text1" />
<input type="text" name="text2" />
<input type="submit" value="提交" name="dosubmit" />
<input type="reset" name="soreset" value="重置" />
</form>
</body>
</html>