在函数中设置剑道下拉值

Set a kendo dropdown value in a function

本文关键字:函数 设置      更新时间:2023-09-26

我有两个剑道下拉列表来选择State作为页面上的地址输入。我有一个复选框,可以将第一个地址复制到第二个地址。我需要能够参考和设置剑道下拉列表的值。

下拉列表:

@(Html.Kendo().DropDownListFor(m => m.physicalAddress.State)
    .Name("physicalAddress.State")
    .DataTextField("name")
    .DataValueField("value") 
    .OptionLabel("Physical State")
    .BindTo((System.Collections.IEnumerable)ViewData["StateList"]))
@(Html.Kendo().DropDownListFor(model => model.mailingAddress.State)
    .Name("mailingAddress.State")
    .DataTextField("name")
    .DataValueField("value")
    .OptionLabel("Mailing State")
    .BindTo((System.Collections.IEnumerable)ViewData["StateList"]))

我试图写的函数:

function copyInfo(f) {
        if (document.getElementById("copyCheckBox").checked) {
            //I'm hoping something exists like this
            [SecondDropDown].value = [FirstDropDown].value;
        }
 }

试试这个:

function copyInfo(f) {   
    if (document.getElementById("copyCheckBox").checked) { 
        var FirstDropDown= $("#dropdownlist1").data("kendoDropDownList");
        var SecondDropDown= $("#dropdownlist2").data("kendoDropDownList");   
        SecondDropDown.value(FirstDropDown.value());
    }
 }

其中dropdownlist1和dropdownlist 2是包含元素的DOM ID。

请参阅API演示:http://demos.telerik.com/kendo-ui/dropdownlist/api

价值文档():http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#methods-值