@Html.DropDownListFor(model => model.State, new SelectList(Model._listAllStateVModel.ListAllStates, "Abbreviations", "Name"), "Select.....", new { ..... })
@Html.DropDownListFor(model => model.County, new SelectList(Model._listAllCountyVModel.ListAllCounty, "CountyId", "CountyName"), "Select.....", new { ..... })
我在DropDownListFor(model => model.State)
& DropDownListFor(model => model.County) + the word "Other..."
中的县名单,
我想要的是当我选择除德州以外的任何州DropDownListFor郡必须改为“其他......”。
我怎么能用jQuery ???
答案 0 :(得分:0)
试试这个..
<select Id="State">
<option value="Texas">Texas</option>
<option value="Sidney">Sidney</option>
<option value="Gujarat">Gujarat</option>
</select>
<select Id="Country">
<option value="USA">USA</option>
<option value="Other">Other</option>
</select>
$('#State').change(function() {
if ($('#State option:selected').text() != 'Texas') {
$('#Country').val("Other").attr("selected", "selected");
}
else{
$('#Country').val("USA").attr("selected", "selected");
}
})
您还可以检查值而不是文本
答案 1 :(得分:0)
这项工作很好.....
$('#State').change(function () {
if ($('#State option:selected').text() != 'Texas') {
$('#County').val('Other').attr("selected", "selected");
}
else {
$('#County').val(null).attr("selected", "selected");
}
});
谢谢