繁体   English   中英

jQuery验证后未提交表单

[英]Form Not Submitting after Jquery Validation

$('form#injuryReportSubmit').submit(function(){             
if(($('form#injuryReportSubmit textarea.description').val().length <=0) || ($('form#injuryReportSubmit select.part').val()== "choose one...") ||($('form#injuryReportSubmit select.type').val() == "choose one...") || ($('form#injuryReportSubmit select.weather').val()=="choose one..."));
            {  
                $('div#errorMessage').show();
                return false;
            }           
}); 

上面的代码用于在表单提交之前对其进行验证。 问题是即使所有测试都为假,表单也不会提交。 有人可以帮忙吗? 表单在一个jsp上,看起来像

<form id ="injuryReportSubmit" method ="post" action="injuryReportingPage.html" >
        <p class ="first" >Date Of Injury</p>
        <p class ="second">Date Reported to Manager</p>
        <input type="text" id="dateOfInjury" name="dateOfInjury">       
        <input type="text" id="dateReported" name ="dateReported">
        <p class ="weather">Weather</p>
        <p class ="injuryType">Injury Type</p>
        <p class ="bodyPart">Body Part</p>
        <p class ="time">Time Injury Occurred</p>
        <p class ="description">Description</p>
        <select class ="weather" name="weather">
        <%if(InjuryReportController.getWeatherList() != null){ %>   
        <%   for(Weather weather : InjuryReportController.getWeatherList()){%>
        <option><%= weather.getWeatherCondition() %></option>
        <%} }%>
        <option >choose one...</option>
        </select>

        <select class ="type" name="injuryType">        
        <%if(InjuryReportController.getInjuryTypeList() != null){ %>    
        <%   for(InjuryType injuryType : InjuryReportController.getInjuryTypeList()){%>
        <option><%= injuryType.getInjuryTypeName() %></option>
        <%} }%>
        <option>choose one...</option>
        </select>

        <select class ="part" name="bodyPart">      
        <%if(InjuryReportController.getBodyPartList() != null){ %>  
        <%   for(BodyPart bodyPart : InjuryReportController.getBodyPartList()){%>
        <option><%= bodyPart.getBodyPartName() %></option>
        <%} }%>
        <option >choose one...</option>
        </select>

        <input type="text" id="timeP" name ="timeOfInjury" value="01:00  AM">
        <textarea class ="description"  rows="120" cols="670" name="description"></textarea>

        <input id ="report" value="Submit Report" type ="submit">

        </form>

从代码第5行的末尾删除分号。

目前您所拥有的是这样的:

if (/*your conditions*/);        // <- note the semicolon
{
    ...
    return false;
}

这意味着带有花括号的块不与if语句关联,因此每次都会执行。 显然然后每次返回false都会取消每个提交。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM