我正在使用 JQuery Validate 插件,并以这种方式验证输入。提交一次表单后,输入已被标记为无效。
有一个字段“from”,其值链接到另一个字段“to”。更改“来自”后,如何让“to”字段重新验证?
HTML:
<div id="fromPanel" class="inputPanel">
<label>From</label>
<div class="invalid valid" generated="true" for="from"></div>
<select id="from" class="campusChooser valid" required="required" name="from">
<option value="" disabled="disabled"> -- Choose a Campus -- </option>
<option selected="selected" value="UTSG">St. George</option>
<option value="UTM">Mississauga</option>
</select>
</div>
<div id="toPanel" class="inputPanel">
<label>To</label>
<div class="invalid" generated="true" for="to"></div>
<select id="to" class="campusChooser" required="required" name="to">
<option value="" disabled="disabled"> -- Choose a Campus -- </option>
<option value="UTSG">St. George</option>
<option selected="selected" value="UTM">Mississauga</option>
</select>
</div>
JS:
$(function () {
$("#to").change(function() {
var otherField = field == "to" ? "from" : "to", otherValue;
if (value == "UTSG") {
otherValue = "UTM";
} else if (value == "UTM") {
otherValue = "UTSG";
} else {
otherValue = "";
}
$("#" + otherField).find("option[value='{0}']".format(otherValue)).prop("selected", true);
});
});