onsubmit 事件入门 sample

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<form action="/a/Abc" onsubmit="return abc();">
	<input type="submit" value="submit"><br>
	<button onclick="mysubmit()">按钮提交</button>
</form>

</body>
</html>
<script>
function abc(){
	alert("onsubmit");
	return false;
}

function mysubmit(){
//直接提交form表单,前面的window可以省略
	window.submit();
}
</script>

 

备注:在form标签中添加的onsubmit事件一定要有return ,如果是false则不会提交请求,否则则会提交请求给服务器。

 

你可能感兴趣的:(sample)