Javascript 如何在剑道UI jQuery中获取下拉列表的选定文本?
我使用的是Kendo UI jQuery版本2019.2.514。我有一个代码片段Javascript 如何在剑道UI jQuery中获取下拉列表的选定文本?,javascript,jquery,kendo-ui,Javascript,Jquery,Kendo Ui,我使用的是Kendo UI jQuery版本2019.2.514。我有一个代码片段 <input id="skuCode" name="skuCode" style="width: 100%;"/> <input id="productName" name="productName" style="width: 100%;"/> <script> $(document).ready(function () { var data = ne
<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>
网页有2个输入:skuCode是一个下拉列表。productName是一个输入文本框。当skuCode具有事件更改时,我希望textbox productName的设置值自动等于选定下拉列表的文本标签,而不是选定下拉列表的值,但仍允许用户编辑。如何做到这一点?您可以使用以下方法 Value方法:获取或设置DropDownList的值。 text方法:获取或设置DropDownList的文本 下面是一个例子:
<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());
};
});
如果有什么不正确的地方,请告诉我