将禁用k状态的类应用于文本输入-Kendo UI [英] Applying k-state-disabled class to text inputs - Kendo UI
问题描述
这是我的jsfiddle 演示.
Here is my jsfiddle demo.
<div id="example" class="k-content">
<div class="demo-section">
<p>
<label for="products">Products:</label><input id="products" disabled="disabled" style="width: 300px" />
</p>
<p>
<label>Text:</label><input id="textboxtest" type="text" class="k-textbox" disabled="disabled" value="test" style="width: 300px" />
</p>
</div>
</div>
<script>
$(document).ready(function() {
var products = $("#products").kendoComboBox({
cascadeFrom: "categories",
filter: "contains",
placeholder: "Select product...",
dataTextField: "ProductName",
dataValueField: "ProductID",
dataSource: {
data: [{"ProductName": "ProductName1", "ProductID": "1"}, {"ProductName": "ProductName2", "ProductID": "2"}]
},
index: 0
}).data("kendoComboBox");
});
</script>
如您所见,禁用的文本输入在视觉上与kendoComboBox小部件不同.当禁用状态在应用程序范围内更改时,是否可以向文本输入添加或删除禁用k状态的类?我希望文本输入与小部件具有相同的行为.
As you see the disabled text input is visually different from the kendoComboBox widget. Is there a way to add or remove k-state-disabled class to text inputs when the disabled state changes in application scope? I want to have the same behaviour as widgets for my text inputs.
推荐答案
我认为最简单,更可移植的方法是在设置disabled
属性值时添加/删除k-state-disabled
.
I think that easiest and more portable way of doing it is by adding / removing k-state-disabled
when you set the disabled
property value.
启用文本框的示例:
$("#textboxtest").prop("disabled", false).removeClass("k-state-disabled");
禁用它:
$("#textboxtest").prop("disabled", true).addClass("k-state-disabled");
您的JSFiddle修改了两个按钮,以启用/禁用它 http://jsfiddle.net/KrW6f/5/
Your JSFiddle modified with two buttons for enabling / disabling it http://jsfiddle.net/KrW6f/5/
:另一种可能性是将字段定义为不带dataSource
的autocomplete
.然后,您实际上不需要定义任何CSS类.您的输入字段定义为:
Another possibility is defining the field as an autocomplete
without a dataSource
. Then you actually not need to define any CSS class. Your input field definition would be:
<input id="textboxtest" data-role="autocomplete" type="text" disabled="disabled" value="test" style="width: 300px" />
您可以在其他JSFiddle中看到它: http://jsfiddle.net/OnaBai/94HDF /2/
And you can see it in this other JSFiddle: http://jsfiddle.net/OnaBai/94HDF/2/
这篇关于将禁用k状态的类应用于文本输入-Kendo UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!