简体   繁体   English

如何在Kendo UI jQuery中获取下拉列表的选定文本?

[英]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.

相关问题 使用jQuery从下拉列表中获取选定的文本 - Get selected text from a drop-down list using jQuery 如何使用JavaScript / JQuery获取下拉列表的选定值 - How to get the selected value of a drop-down list with JavaScript/JQuery 从下拉列表中获取所选文本,但使用jQuery删除数值 - Get selected text from a drop-down list but remove numeric value using jQuery 使用 jQuery 从下拉列表(选择框)中获取选定的文本 - Get selected text from a drop-down list (select box) using jQuery 如何使用 jQuery 覆盖下拉列表的选定值 - How to override the selected value of a drop-down list with jQuery 下拉菜单中获得所选项目的文本 - Drop-down get Selected item Text 如何使用jquery从filterToolbar的下拉列表中获取选定的值 - How to get selected values from drop-down list in filterToolbar using jquery 自动将下拉列表中的选定文本复制到剪贴板 - Autocopy selected text on drop-down list to clipboard 使用 jQuery 更改下拉列表的选定值 - Change the selected value of a drop-down list with jQuery 如何使用取决于另一个下拉列表中所选选项的下拉列表显示表格简码 - how to display table shortcode with a drop-down list that depends on the selected option in another drop-down list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM