gpt4 book ai didi

asp.net-mvc - 在复选框选择上启用/禁用 'DropDownListFor'

转载 作者:行者123 更新时间:2023-12-04 11:52:55 24 4
gpt4 key购买 nike

我正在显示选中复选框时的下拉值。但是使用下面的代码,下拉列表中的所有不同项目都会直接出现。

@Html.DropDownListFor 无法在 select 标签内工作,谁能帮我解决这个问题?

注意:复选框切换功能完美无缺。

谢谢,

.cshtml

<input type="checkbox" /> 
<p>check this box to escalate</p>
<select disabled="disabled">
@Html.DropDownListFor(
model => model.EscalationQueue,
new SelectList(Extensions.EscalationQueue, Model.EscalationQueue),
new { @class = "escalation-queue", name = Model.EscalationQueue }
)
</select>

.js文件

var dropdownToggle = function () {
$("input:checkbox").change(function () {
if ($("input:checkbox").is(":checked")) {
$("select").removeAttr("disabled");
}
else {
$("select").attr("disabled", "disabled");
}
});
}

$(document).ready(function () {
dropdownToggle();
});

输出:

CurrentOutput1

CurrentOutput2

最佳答案

你不需要 <select>标记,HtmlHelper DropDownListFor将为您呈现。如果您想将下拉列表初始化为禁用,请像声明 cssclass 一样设置 html 属性...

<input type="checkbox" /> 
<p>check this box to escalate</p>
@Html.DropDownListFor(
model => model.EscalationQueue,
new SelectList(Extensions.EscalationQueue, Model.EscalationQueue),
new { @class = "escalation-queue",
name = Model.EscalationQueue,
disabled= "disabled"
}
)

关于asp.net-mvc - 在复选框选择上启用/禁用 'DropDownListFor',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11043297/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com