gpt4 book ai didi

java - Jquery 验证后表单未提交

转载 作者:行者123 更新时间:2023-12-01 15:34:25 24 4
gpt4 key购买 nike

$('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;
}

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

关于java - Jquery 验证后表单未提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9122401/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com