在提交表单中,返回false不起作用 [英] On submit form, return false not working
本文介绍了在提交表单中,返回false不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我提交表单时,我收到了一条警告消息。当我接受警报时,它仍然会提交表格。返回false将被忽略。
Onclick无法使用。我尝试使用 var x = document.forms [form] [fname] .value;
并且仍然相同。
< form id =fmethod =postname =formonsubmit =return validateForm(); 行动= # >
< input type =textname =fnameid =test/>
< input type =submitvalue =submit/>
< / form>
< script type =text / javascript>
函数validateForm(){
var x = document.getElementById('test')。value;
if(x == null || x == 0 || x ==0){
alert(Stop);
返回false;
}
}
< / script>
解决方案
替代< input type =submitvalue =submit/>
use < input type =buttonvalue =Submitonclick ='validateForm()'/>
。
在您的JS中:
< script type =text / JavaScript的>
函数validateForm(){
var x = document.getElementById('test')。value;
if(x == null || x == 0 || x ==0){
alert(Stop);
}
else
document.form.submit();
}
< / script>
When I submit the form I got an alert message. When I accept the alert it will submit the form anyway. Returning false is ignored.
Onclick can not be used. I try with var x = document.forms["form"]["fname"].value;
and still same.
<form id="f" method="post" name="form" onsubmit="return validateForm();" action="#">
<input type="text" name="fname" id="test" />
<input type="submit" value="submit"/>
</form>
<script type="text/javascript">
function validateForm() {
var x = document.getElementById('test').value;
if (x == null || x == 0 || x == "0") {
alert("Stop");
return false;
}
}
</script>
解决方案
Instead of <input type="submit" value="submit"/>
use <input type="button" value="Submit" onclick='validateForm()'/>
.
In your JS:
<script type="text/javascript">
function validateForm() {
var x = document.getElementById('test').value;
if (x == null || x == 0 || x == "0") {
alert("Stop");
}
else
document.form.submit();
}
</script>
这篇关于在提交表单中,返回false不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文