我有两个带有相同问题的下拉列表。我必须“不显示”从第一个下拉列表中选择的项目,反之亦然。如果我从第一个下拉列表中选择了问题 1,它将在第二个下拉列表中不可用。
下面是我的代码:
<div class="form-group">
@Html.DropDownListFor(m => m.ChallengeQuestion1, (SelectList)ViewBag.ChallengeQuestions, "-- Challenge Question 1 --", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.ChallengeQuestion1)
</div>
<div class="form-group">
@Html.TextBoxFor(m => m.ChallengeAnswer1, new { @class = "form-control", placeholder = "Answer" })
@Html.ValidationMessageFor(m => m.ChallengeAnswer1)
</div>
<div class="form-group">
@Html.DropDownListFor(m => m.ChallengeQuestion2, (SelectList)ViewBag.ChallengeQuestions, "-- Challenge Question 2 --", new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.ChallengeQuestion2)
</div>
<div class="form-group">
@Html.TextBoxFor(m => m.ChallengeAnswer2, new { @class = "form-control", placeholder = "Answer" })
@Html.ValidationMessageFor(m => m.ChallengeAnswer2)
正如斯蒂芬已经告诉你必须在客户端做的那样。
var $dropdown1 = $("select[name='dropdown1']");
var $dropdown2 = $("select[name='dropdown2']");
$dropdown1.change(function() {
var selectedItem = $(this).val();
$("select[name='dropdown2'] > option[value=" +selectedItem +"]").attr('disabled', true)
.siblings().removeAttr('disabled');
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句