3

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

不知何故,@Html.DropDownListFor 在选择标签内不起作用,有人可以帮我修复它吗?

注意:复选框切换完美。

谢谢,

.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();
});

输出:

电流输出1

电流输出2

4

1 回答 1

4

您不需要<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" 
         }
)  
于 2012-06-15T00:53:00.363 回答