[英]How to get selected text of drop-down list in Kendo UI jQuery?
I am using Kendo UI jQuery version 2019.2.514
. 我正在使用Kendo UI jQuery版本
2019.2.514
。 I have code snippet 我有代码片段
<input id="skuCode" name="skuCode" style="width: 100%;"/>
<input id="productName" name="productName" style="width: 100%;"/>
<script>
$(document).ready(function () {
var data = new kendo.data.DataSource({
transport: {
read: {
url: "/sku_json",
dataType: "json"
}
},
pageSize: 30
});
// create DropDownList from input HTML element
$("#skuCode").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: data,
filter: "contains",
index: 0,
change: onChange
});
});
// Set selected text value of Drop-down list --> value of input productName.
function onChange() {
// document.getElementById("productName").value = document.getElementById("skuCode").value; // Return selected value of drop-down list
// document.getElementById("productName").value = document.getElementById("accountObjectCode").text; // I try something like this, but not work.
}
</script>
Web page has 2 inputs: skuCode
is a drop-down list. 网页有2个输入:
skuCode
是一个下拉列表。 productName
is a input textbox. productName
是一个输入文本框。 When skuCode
has event onChange
, I want set value of textbox productName
automatically (equal the text label of selected drop-down list, not value of selected drop-down list), but still allow user edit. 当
skuCode
活动onChange
,我要设置文本框的值productName
自动(等于选定的下拉列表中,而不是选择下拉列表中值的文本标签),但仍然允许用户编辑。 How to do this? 这个怎么做?
You can do with help of following method. 您可以借助以下方法进行操作。
Value method : Gets or sets the value of the DropDownList. 值方法:获取或设置DropDownList的值。 text method : Gets or sets the text of the DropDownList.
text方法:获取或设置DropDownList的文本。
Here is example : 这是示例:
<input id="skuCode" name="skuCode" style="width: 100%;"/>
<input id="productName" name="productName" style="width: 100%;"/>
<script> $(document).ready(function() {
$("#productName").kendoDropDownList({
dataSource: [
{ id: 1, name: "Apples" },
{ id: 2, name: "Oranges" }
],
dataTextField: "name",
dataValueField: "id",
change: onChange
});
function onChange(e) {
// You can do with this also
// $("#skuCode").val($("#productName").data("kendoDropDownList").text());
$("#skuCode").val(e.sender.text());
};
});
Let me know if anything incorrect. 让我知道是否有任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.