日期:2014-05-19  浏览次数:20632 次

form的onsubmit总是提交,高手进来
JScript code
<script language="javascript" type="text/javascript">
function retur(){
    return false;
}
function Formfield(name, label){
    this.name=name;
    this.label=label;
}
function clearForm(name){
    this.name=name;
}
function verifyForm(objForm){
    var clearnull = new Array(
            new clearForm("name"),new clearForm("type"),new clearForm("baseprice"),new clearForm("marketprice"),new clearForm("sellprice"),
            new clearForm("stylename"),new clearForm("logoPath")
            );
    for(var i=0;i<clearnull.length;i++){
        var clearobj = eval("objForm."+ clearnull[i].name);
        if(trim(clearobj.value)!="" || trim(clearobj.value)!=0.0){
            $("#"+clearnull[i].name).html("");
        }
    }
    var list  = new Array(new Formfield("name", "产品名称"),new Formfield("type", "产品类型"),
    new Formfield("baseprice", "产品底价"),new Formfield("marketprice", "产品市场价")
    ,new Formfield("sellprice", "产品销售价"),new Formfield("stylename", "产品图片的样式"),new Formfield("logoPath", "产品图片"));
    for(var i=0;i<list.length;i++){
        var objfield = eval("objForm."+ list[i].name);
        if(trim(objfield.value)==""){
            $("#"+list[i].name).html(list[i].label+ "不能为空");
            if(objfield.type!="hidden" && objfield.focus()) objfield.focus();
            return false;
        }
    }
    return true;
}
</script>


<s:form name="example" action="/conter/product/add" enctype="multipart/form-data" method="post" onsubmit="return verifyForm(this)">

第一次判断是可以的,但是第二次判断表单就直接提交了,求高手打救

------解决方案--------------------
表单验证有错误,哪里有错误 ,一步步试就出来了 

------解决方案--------------------
验证逻辑肯定是不对嘛,单步一下看到哪儿不是你想要的
------解决方案--------------------
enctype="multipart/form-data"会不会有问题,去掉试试
------解决方案--------------------
验证不符合后要换回;不换回就直接提交鸟