我有一个下拉列表,其中列出了用户可以生成的报告类型,一旦他们选择了报告类型,它将显示另一个下拉列表,如此屏幕截图所示。
<select name="type_of_report" id="type_of_report">
<option value="" selected="selected"></option>
<option value="all_students">All students</option>
<option value="state">State</option>
<option value="sport_id">Sport</option>
<option value="major_id">Interest of Study</option>
<option value="graduation_year">High School Graduation Year</option>
<option value="recruitment_place_id">Where they heard about us</option>
</select>
如果他们选择状态,我想要求状态字段。
理论上,这是我想做的:
$("#type_of_report").live("change", function() {
var report_selected = $("#type_of_report").val();
});
$("form").validate({
rules: {
if(report_selected != '') {
report_selected: { required: true },
}
type_of_report: { required: true }
}
});