【问题标题】:Form Not Submitting after Jquery ValidationJquery验证后表单未提交
【发布时间】:2012-02-25 16:50:53
【问题描述】:
$('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>

【问题讨论】:

    标签: java javascript hibernate spring


    【解决方案1】:

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

    目前你得到的是这样的:

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

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

    【讨论】:

    • 您说的完全正确,我不知道我怎么没看到...非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多