在我的名为 frmClock 的表单中,我有一个 div,它最终用作 jQuery UI 模式对话框的基础:
<div id="dialog-form-clockout" title="Associate Mileage Reimbursement" data-ok="<%=clkContinueClockOut%>" data-cancel="<%=clkCancel%>" data-errornum="Invalid number format. Valid number format is 999.9" data-errorzero="Please enter a value greater than zero. Otherwise, select No." data-errormaxchars="Please enter a numeric value less than 5 characters long." data-errornoradio="Please select Yes or No.">
<fieldset>
<div id="personalVehicle">
<label for="<%=TAConstants.FN_ASM_RESPONSE%>">Did you use your personal vehicle for business travel during this shift?</label>
<br>
<input type="radio" name="<%=TAConstants.FN_ASM_RESPONSE%>" id="personalvehicle" class="text ui-widget-content ui-corner-all" value="Y"/>Yes
<input type="radio" name="<%=TAConstants.FN_ASM_RESPONSE%>" id="personalvehicle" class="text ui-widget-content ui-corner-all" value="N"/>No
<br>
</div>
<div id="questionsY" class="hidden">
<div class="modalDialogQuestions">
<label for="<%=TAConstants.FN_BANK_ROUND_TRIPS%>" class="modalDialogQuestionsLbl">Enter number of round-trips to the bank.</label>
<select name="<%=TAConstants.FN_BANK_ROUND_TRIPS%>" class="modalDialogAnswers" id="roundtrips">
<option selected value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
<div class="modalDialogQuestions">
<label for="<%=TAConstants.FN_OTHER_MILES%>" class="modalDialogQuestionsLbl">Enter number of miles for business related travel other than the bank.</label>
<input class="positive modalDialogAnswers" type="number" name="<%=TAConstants.FN_OTHER_MILES%>" id="mileage" value="0.0" maxlength=5/>
</div>
</div>
</fieldset>
<div class="ui-state-error hidden" style="height:auto;"><span class="ui-icon ui-icon-alert" style="display:inline; margin-right:.25em; float:left;"/></span><p class="validateTips" style="display:inline; border:0px;"></p></div>
</div>
</form>
所以最终,一旦我们填写了这个 jQuery 模态对话框表单,我会使用我们在此增强之前使用的相同 javascript 来提交表单(加上警报,告诉我这个数据在文档元素中)。
alert(document.getElementById('personalvehicle').value);
alert(document.getElementById('roundtrips').value);
alert(document.getElementById('mileage').value);
submitForm();
...
/**
* This function disallows the form to be submitted twice.
*/
function submitForm () {
if (!hasBeenSubmitted) {
hasBeenSubmitted = true;
document.frmClock.submit();
}
警报显示与用户输入的文本相同的文本,但似乎不会与我们过去在没有 jQuery 模态对话框表单的情况下收到的其余表单数据一起发送。我一直在从我们的处理器 .java 文件中确定这一点,下面的代码似乎没有设置变量,因为它没有通过空检查:
if (req.getParameter(FN_ASM_RESPONSE)!=null){
Character asmResponse = (req.getParameter(FN_ASM_RESPONSE)).charAt(0);
}
if (req.getParameter(FN_BANK_ROUND_TRIPS)!=null){
Integer bankRoundTrips = Integer.parseInt(req.getParameter(FN_BANK_ROUND_TRIPS));
}
if (req.getParameter(FN_OTHER_MILES)!=null){
Float otherMiles = Float.parseFloat(req.getParameter(FN_OTHER_MILES));
}
我听到的最多的是确保我的输入具有name
属性。虽然这些名称属性似乎已设置,但查看源代码将它们显示为personalvehicle,
roundtrips
, 和mileage
,它们是从以下常量 .java 文件中设置的:
public static final String FN_ASM_RESPONSE = "personalvehicle";
public static final String FN_BANK_ROUND_TRIPS = "roundtrips";
public static final String FN_OTHER_MILES = "mileage";
有人对我应该研究或尝试什么有任何想法吗?getParameter() 方法上的断点用于检查 null 是否显示它命中这些点,但由于参数为空,因此未命中所包含的内容。