首先 action在form是属性,onsubmit是事件。
<form action="table1.jsp" onSubmit="return check();">
<div><input type="text" id="in" value="helloWord"/>
<input type="submit" value="提交" />
</div>
</form>
function check(){
var oText = document.getElementById("in").value;
alert(oText);
if(oText =="false"){
return false;
}
else {
return true;}
}
要说执行的先后顺序,onSubmit在先,先验证,验证返回false时,则无法到达action="url"地址。如果是返回true或者没有返回值,则通过action转向url地址。
也就是说onsubmit可以阻止action的提交
onSubmit="return check();" 这里的return是一定要写的。不可写成onsubmit=check();