首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我正在尝试使用mvc JavaScript函数启用/禁用dropdowns

我正在尝试使用mvc JavaScript函数启用/禁用dropdowns
EN

Stack Overflow用户
提问于 2019-03-07 01:28:44
回答 1查看 23关注 0票数 0

当未选中Enable checkBox时,我正在尝试禁用这些下拉列表。这是我在这方面的第一次,任何指导都将不胜感激。

基本上,当checkBox被禁用时,我会尝试禁用下拉列表。选中checkBox时,需要启用下拉列表。

js:

代码语言:javascript
复制
$(document).ready(function () {
    if ($("#userPermissions").checked) {

        enableAll();
        console.log("enableAll");
    } else {
        disableAll();
        console.log("disableAll");
    }
})

$('#userPermissions').change(function (e) {
    //console.log('change');
    if (this.checked) {
        enableAll();
        console.log('change1');
    } else {
        disableAll();
        console.log('change2');
    }
});

function enableAll() {
    $("#userSettingsBottom  :input").prop("disabled", false);
    console.log("enabled");
}
function disableAll() {
    $("#userSettingsBottom  :input").prop("disabled", true);
    console.log("disabled");
}

cshtml:

代码语言:javascript
复制
<section class="well ">
<div class="row">
    <div class="col-lg-12 gutter-0">

        <div class="row gutter-0">                
            <div class="col-sm-6 col-md-6 col-lg-8">
                <div class="box-placeholder">
                    <div>
                        @Html.Label(Resources.USERS_Settings, htmlAttributes: new { @class = "control-label", maxlength = "15", style = "font-weight: bold; font-size: 15px; display: inline;" })
                    </div><br />
                    <div>
                        @Html.Kendo().CheckBoxFor(model => model.EnableUserLogin.BoolValue).Label(Resources.Users_EnableSecurity).HtmlAttributes(new { @class = "cti-db-numvalue cti-up-EnableUserLogin", id = "userPermissions", type = "checkbox" })

                        @Html.ValidationMessageFor(model => model.EnableUserLogin, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-12 gutter-0">               
            <div class="col-sm-6 col-md-6 col-lg-8">
                <div class="box-placeholder">
                    @Html.Kendo().CheckBoxFor(model => model.EnableTransferOnLoginScreen.BoolValue).Label(Resources.Users_EnableTransferOnLoginScreen).HtmlAttributes(new { @class = "cti-db-numvalue cti-up-EnableTransferOnLoginScreen" })
                </div><hr />
            </div>
        </div>
    </div>
    <div class="col-sm-12 col-md-12 col-lg-12">
        <div class="row gutter-10">
            <div class="col-sm-6 col-md-6 col-lg-8">
                <div id="userSettingsBottom" class="box-placeholder" style="outline: none;">
                    <div>
                        @Html.Label(Resources.USERS_CustomFieldOption, htmlAttributes: new { @class = "control-label", style = "font-weight: bold; font-size: 14px; display: inline;" })&nbsp
                        @Resources.USERS_SelectedField
                    </div>
                    <div class="col-sm-4 col-md-4 col-lg-4">
                        <div>
                            @Html.Label(Resources.Users_InboundUserIDField, htmlAttributes: new { @class = "control-label" })
                        </div>
                        @Html.Kendo().DropDownListFor(model => model.InboundUserIDField).HtmlAttributes(new { @class = "cti-db-numvalue cti-up-InboundUserIDField" })
                    </div>
                    <div class="col-sm-4 col-md-4 col-lg-4">
                        <div>
                            @Html.Label(Resources.Users_DeliverUserIDField, htmlAttributes: new { @class = "control-label" })
                        </div>
                        @Html.Kendo().DropDownListFor(model => model.DeliverUserIDField).HtmlAttributes(new { @class = "cti-db-numvalue cti-up-DeliverUserIDField" })
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

EN

回答 1

Stack Overflow用户

发布于 2019-03-07 01:43:55

既然这些都是剑道下拉菜单,为什么不使用剑道功能呢?首先,名称应该从model字段派生。在这种情况下,model.DeliverUserIDField的默认示例为

代码语言:javascript
复制
$("#DeliverUserIDField").data("kendoDropDownList").enable(false);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55028956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档