显然我对理解JS有一个问题。我是新手,我试图让它适用于以下用例:
如果从“纪律”下拉列表中选择“医疗保健”,则在其他下拉列表中将不会显示“私人部门”选项。
<div class="col-md-6 jurisdictionParentDiv">
<div class="form-group">
@Html.LabelFor(m => m.Jurisdiction, new { @class ="control-label" })
@Html.DropDownListFor(
m => m.Jurisdiction,
GlobalLists.JurisdictionList
.Where(k => k.Key != "Military")
.Select(
k => new SelectListItem {
Text = k.Value,
Value = k.Key,
Selected = k.Value == Model.Jurisdiction
}),
"-- Select --",
new { @class = "form-control input-sm" }
)
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
@Html.LabelFor(m => m.Discipline, new { @class = "control-label" })
@Html.DropDownListFor(
m => m.Discipline,
GlobalLists.DisciplineList
.Select(
k => new SelectListItem {
Text = k.Value,
Value = k.Key,
Selected = k.Value == Model.Discipline
}),
"-- Select --",
new { @class = "form-control input-sm" }
)
</div>
</div>
<script>
$(document).ready(function() {
$('#Jurisdiction').change(function () {
var el = $('#Discipline');
if (el.val() === 'Healthcare') {
$('#Jurisdiction').remove('Private Sector')
}
});
});
</script>
答案 0 :(得分:0)
你可以这样做,
if ($('#Discipline').val() === "Healthcare") {
$("#Jurisdiction option[value='Private Sector']").hide();
}