【发布时间】:2017-10-02 14:27:09
【问题描述】:
我想显示一个带有 texbox 的 div,只有当下拉列表中选择的项目文本等于“其他”时
从下面,我只想在选择下拉列表项文本“其他”时显示一个 div 'divOtherIncident'。如果选择了其他内容,则 弹出窗口应该出现(这个位工作正常)
我这里有两个问题。
1) 对于包括“其他”在内的所有选定项目文本,它总是进入其他条件。我可以看到警报显示其他文本,但它永远不会进入 if 条件 2) div 从不显示或隐藏,
谁能帮忙。
<div class="form-group">
@Html.LabelFor(model => model.SelectedIncident, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-9">
@Html.DropDownListFor(model => model.SelectedIncident, new SelectList(string.Empty, "Value", "Text"), new { data_toggle = "popover", @class = "form-control", @id = "IncidentId" })
@Html.ValidationMessageFor(model => model.SelectedIncident, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group hidden" id="divOtherIncident">
@Html.LabelFor(model => model.OtherIncident, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-9">
@Html.EditorFor(model => model.OtherIncident, new { htmlAttributes = new { @class = "form-control", @id = "tbOtherIncident"} })
</div>
</div>
$("#IncidentId").change(function () {
var ddlOIValue = $("#IncidentId option:selected").text();
alert(ddlOIValue); //This displays the text 'Other' but it never goes into if condition below
if (ddlOIValue == "Other") {
$('#divOtherIncident').show();
}
else {
$('#divOtherIncident').hide();
$("#tbOtherIncident").val("");
$.ajax({
type: 'GET',
url: '@Url.Action("GetActionDetails")',
dataType: 'html',
data: { id: $("#IncidentId").val() },
success: function (data) {
$('[data-toggle="popover"]').popover({
html: true,
content: data
});
},
error: function (ex) {
alert('Failed to retrieve action details' + ex);
}
});
return false;
}
});
【问题讨论】:
标签: jquery asp.net-mvc twitter-bootstrap