为什么硬编码值对按钮有效,而对其他按钮无效?

why hard coded value work on button and not work on another?

本文关键字:按钮 其他 无效 有效 编码值 为什么      更新时间:2023-09-26

我有两个按钮都有相同的代码,唯一的区别是参数。一个函数给出正确的输出和其他给出未定义。我在我的演示中使用jtree。

第一个按钮是"子",其中我硬编码"b"并获得子值。第二个按钮是"next",我硬编码"c",并获得未定义的子值。小提琴http://jsfiddle.net/fuu94/69/

    $('#next').click(function () {

            $('#tree').jstree(true) .select_node('c')
            alert($('#tree').jstree(true).get_node( 'c').children);

    });

$('#child').click(function () {
    $('#tree').jstree(true) .select_node('b')
    alert($('#tree').jstree(true).get_node('b').children)
for(i in $('#tree').jstree(true).get_node('b').children){    //alert($('#tree').jstree(true).get_text($('#tree').jstree(true).get_node('b').children[i.toString()]));
}
});

尝试从

更改id
<li id="c-1">c

<li id="c">c