我打算做的是:首先验证表格,然后处理是否满足某些条件。我已粘贴下面的代码原型。 我已经交叉检查了任何轻微/愚蠢的错误。感谢
代码:
<form id = "myform" action = process.php method = 'post'>
//some form elements here
<input type="submit" value="Submit this form"onclick="validate();return false;" />
</form>
<script type="text/javascript">
function validate(){
if(validated) myform.submit();
else Alert(Some message);
</script>
}
答案 0 :(得分:1)
我认为你需要做这样的事情:
<form id="myform" action="process.php" method="post" onsubmit="return validate();">
//some form elements here
<input type="submit" value="Submit this form" />
</form>
<script type="text/javascript">
function validate(){
...
if(!valid)
alert('Error');
return valid;
}
</script>