您现在的位置是:首页 > 电脑技术查询 > web开发

javascript修改form里的一些值以后怎么阻止页面提交

编辑:chaxungu时间:2022-10-02 23:22:14分类:web开发

javascript修改form里的一些值以后如何阻止页面提交?
<script>

function check()

{
f1.a.value=asd
//alert(f1.a.value)
return false;
}

</script>
<form action=/cgi-bin/a.cgi id=f1>
<input type=radio name= "a1 " value=a id=a>
<input type=radio name= "a1 " id=b value=b>
<input type=submit value=submit value=submit onclick= "return check() ">
</form>


无论我如何return false
页面总是会提交,万一验证不通过,我需要阻止啊,可是现在我不能。
怎么办?请教各位了

------解决方案--------------------
你可以不用Submit控件啊,就用button,等Check完了后,再调用Submit方法 : f1.submit();就可以了
------解决方案--------------------
1、设置action= " "
2、在check()中判断,如果通过,再设置action,提交,不通过,则return
如:document.getElementById( "f1 ").action = "/cgi-bin/a.cgi ";
document.getElementById( "f1 ").submit();
------解决方案--------------------
我试了不提交呀
改成true就提交了
------解决方案--------------------
在form里面onSubmit= "return check() "
function check()

{
if(f1.a.value=asd)
return false;
return true
}