前言:
1> onsubmit 事件会在表单中的确认按钮被点击时发生
2>onreset 事件会在表单中的重置按钮被点击时发生
代码示例如下:
1> onsubmit 事件会在表单中的确认按钮被点击时发生
2>onreset 事件会在表单中的重置按钮被点击时发生
代码示例如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus?">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>提交与重置事件</title>
</head>
<script type="text/javascript">
<!--
function check(form){
//拿到文本框中的内容
var txt = form.username.value ;
//判断内容
if(txt == ""){
document.getElementById("sname").innerHTML = " <font color = red>* 姓名必须填写</font>" ;
form.username.focus() ;
return false;
}
return true ;
}
function fun(form){
alert("重置事件") ;
return true ;
}
//-->
</script>
<body>
<form method="post" action="01-鼠标的单击事件.html" onsubmit = "return check(this)" onreset = "return fun(this)">
<!--
1.提交或重置事件必须在form中填写
2.return check(this)或return fun(this)语句中的return关键字必须写上,
因为这是提交给浏览器的,浏览器根据form的return的结果为true或false,
从而决定是否提交或重置,true表示是,false表示否
-->
姓名:<input type="text" name="username"><span id = "sname"></span><br>
<input type="submit" value = "提交">
<input type="reset" value = "重置">
</form>
</body>
</html>