js 表單事件
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');
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>