问题描述
我有两种在FireFox中行为不端的表单,但在IE中工作正常。
当我提交(使用提交按钮)时,javascript函数验证所有字段输入,如果出现错误则停止提交。
示例(显然不是正常工作代码):
[HTML]< html>
< head>
< script type =" text / javascript">
功能提交()
{
//在提交之前做一些事情,比如表格字段验证
返回true;
}否则{
返回false; //什么都不做,不要提交表格
}
}
< / script>
< ; / head>
< body>
< form name =" myForm"行动= QUOT; form.cgi" onSubmit =" return Submit()>
这里的一些表格字段< br />
< input type =" submit"值= [提交" >
< / form>
< / body>
< / html>
[/ HTML]
问题:
在IE中,脚本执行为预计。
在FireFox中(在v2.0.0.3中测试):
*如果表单验证正确,则会提交两次:
*如果表单没有验证那么什么也没发生。
我在这里编码错了吗?为什么FireFox提交表单两次..
I have a couple of forms that are misbehaving in FireFox, but work fine in IE.
when i do submit( with submit button) a javascript function validates all of the fields entered, and stops the submission if there is an error.
Sample (obviously not working code):
[HTML] <html>
<head>
<script type="text/javascript">
function Submit()
{
// do something, like form field validation before submitting
return true;
} else {
return false; // do nothing, do not submit the form
}
}
</script>
</head>
<body>
<form name="myForm" action="form.cgi" onSubmit="return Submit()>
Some form fields here<br/>
<input type="submit" value="Submit" >
</form>
</body>
</html>
[/HTML]
THE PROBLEM:
In IE, the script performs as expected.
In FireFox (tested in v2.0.0.3):
* if the form validates correctly, it gets submitted twice:
* if the form doesn''t validate then nothing happen.
Am I coding something wrong here? Why is FireFox submitting the form two times..
推荐答案
我不是FireFox的大师,我只是在这里试试运气,
如果你调用onClick函数onClick而不是onSubmit形式会发生什么?
I''m not a FireFox guru and am just trying my luck here,
What happens if you call the function onClick of the submit button rather than onSubmit of the form?
当然。应该是它。
Of course. That should be it.
这篇关于FireFox提交表格两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!