Jquery 从剑道下拉列表值选择获取后代

Jquery 从剑道下拉列表值选择获取后代,jquery,kendo-ui,Jquery,Kendo Ui,我正在使用KendoUI框架开发一个web应用程序。HTML文件如下所示:- <div class="grand_parent"> <div class="parent1"> <div class="child1"></div> </div> <div class="spacer"></div> <div class="parent2">

我正在使用KendoUI框架开发一个web应用程序。HTML文件如下所示:-

<div class="grand_parent">

    <div class="parent1"> 
        <div class="child1"></div>
    </div>

    <div class="spacer"></div>

    <div class="parent2">
        <div class="child2"></div>
    </div>

    <div class="spacer"></div>

    <div class="parent3">
        <div class="child3">
             <span>This content will be replaced</span>
        </div>
    </div>

</div>

此内容将被替换
“grand_parent”类将根据条件重复。在这个'child2'类将绑定与剑道dropdownlist

$(".child2").kendoDropDownList({
    dataTextField: "text",
    dataValueField: "value",
    dataSource: options,
    change: onSelect,
    index: 0,
});


options = [
    {text:"Child1", value:1},
    {text:"Child2", value:2},
    {text:"Child3", value:3},
];

function onSelect(e){
    var value = e.sender.value();
    switch (value) {
        case 1:
            $(this).parentsUntil(".parent2").closest(".parent3").find(".child3").html("<span>Value1</span>");
            break;
        case 2:
            $(this).parentsUntil(".parent2").closest(".parent3").find(".child3").html("<span>Value2</span>");
            break;
        case 3:
            $(this).parentsUntil(".parent2").closest(".parent3").find(".child3").html("<span>Value3</span>");
            break;
        default:
            $(this).parentsUntil(".parent2").closest(".parent3").find(".child3").html("<span>value restored</span>");
            break;
    }
}
$(.child2”).kendoDropDownList({
dataTextField:“文本”,
dataValueField:“值”,
数据源:选项,
更改:onSelect,
索引:0,
});
选项=[
{文本:“Child1”,值:1},
{文本:“Child2”,值:2},
{文本:“Child3”,值:3},
];
功能选择(e){
var value=e.sender.value();
开关(值){
案例1:
$(this.parentsUntil(“.parent2”).closest(“.parent3”).find(“.child3”).html(“Value1”);
打破
案例2:
$(this.parentsUntil(“.parent2”).closest(“.parent3”).find(“.child3”).html(“Value2”);
打破
案例3:
$(this.parentsUntil(“.parent2”).closest(“.parent3”).find(“.child3”).html(“Value3”);
打破
违约:
$(this.parentsUntil(“.parent2”).closest(“.parent3”).find(“.child3”).html(“值还原”);
打破
}
}

我的要求是,当我从child2 dropdownlist中选择一个值时,对应的“child3”内容应该被替换。(就像当我从第一行的child2 dropdownlist中选择一个值时,第一行的child3应该被替换)。我怎样才能做到这一点呢?

代码中有很多东西需要修改。 首先,您应该选择“this.element”或“this.wrapper”。 检查此链接:

然后修理你的开关箱。 最后修复jQuery选择器:

$(this.element).closest(".parent2").siblings(".parent3").find(".child3").html("<span>Value1</span>");
$(this.element).最近的(.parent2”).兄弟姐妹(.parent3”).find(.child3”).html(“Value1”);
这里有一个链接,可以查看它的运行情况:


1)如果选择child1或child2而不是child3,会发生什么?2) 在此过程中是否还有其他dropdownlist可操作?(从你上面的问题来看,“child1”和“child3”元素都是简单的div。)3)在switch case中,你写了多次“case1”。@GiovanniRomio:这是错误的。正如您提到的,child1和child3是简单的div。OnCaly child2类将与KendoDropDownList绑定。如果选择child1或child2而不是child3,会发生什么情况?@Giovaniromio:child3>span elemet的文本将被替换。下面的答案是正确的。我认为真正的问题在于“这个”引用。无论如何,谢谢你:):)