简体   繁体   English

根据Kendo-UI下拉列表中的值,启用/禁用复选框

[英]Enable / Disable checkbox depending on value in Kendo-UI dropdown list

I have a Kendo-Ui dropdownlist that is populated with 3 values. 我有一个Kendo-Ui下拉列表,其中填充了3个值。 If the user selects one of the values I need to enable a checkbox. 如果用户选择值之一,则需要启用一个复选框。 If either of the other 2 values are selected then the checkbox needs to be disabled. 如果选择了其他两个值中的一个,则需要禁用该复选框。

I am using .Events and e.Select and have created the function but I am not sure where to go next 我正在使用.Events和e.Select并创建了函数,但是我不确定下一步要去哪里

    <div class="row">
        <div class="form-group col-sm-3">
            <label for="Severity" class="form-label">Severity</label>
            @(Html.Kendo().DropDownList()
                  .Name("SeverityId")
                  .DataTextField("Name")
                  .DataValueField("Id")
                  .OptionLabel("Select Severity...")
                  .DataSource(source =>
                  {
                      source.Read(read =>
                      {
                          read.Action("Get", "Severity", new { area = "Admin" });
                      });
                  })
                  .HtmlAttributes(new {style = "width: 100%"})
                  .Events(e =>
                  {
                      e.Select("onSeverityChange");
                  })
                  )
        </div>
        <div class="form-group col-sm-1">
            <input type="checkbox" class="form-control k-checkbox" id="checkboxFatal" disabled="disabled" />
            <label class="k-checkbox-label" for="checkboxFatal">Fatal</label>
        </div>

        <script>
            function onSeverityChange(e) {
                if (e.dataItem.Name) {
                    $("#Fatal").enabled = true;
                } else {

                }
            }
        </script>

I believe your logic is correct, but the problem is how you're trying to enable/disabled the element. 我相信您的逻辑是正确的,但是问题是您如何尝试启用/禁用该元素。 Try: 尝试:

$("#checkboxFatal").attr("disabled", true);

First, the real id of the element is checkboxFatal and not Fatal . 首先,元素的真实idcheckboxFatal而不是Fatal Then you need to use attr() to change any attribute value in jQuery. 然后,您需要使用attr()更改jQuery中的任何属性值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM