如何在jQuery Treeview中填充特定父节点的子节点



我使用jQuery树视图。是否有一种方法来填充在一个特定的父onclick事件的子节点?请给我一些建议或简单的示例代码来做到这一点。

您可以使用

使用Javascript访问该节点
document.getElementById('theParent')
    .getElementsByTagName('firstHierarchyTag')[n]
    .getElementsByTagName('secondHierarchyTag')[n]
    ...

是的,这是可能的,给我们HTML代码,然后我们将能够给出一个非常具体的例子。

// attach the treeview to the main ul
$("#mytree").treeview();
// listen for an event on a specific node
$("#mytreebranch").click(function() {
    var children = "<li><span class='folder'>New Children</span>"+
                   "<ul><li><span class='file'>Sub-child 1</span></li>" + 
                   "<li><span class='file'>Sub-child 2</span></li>" +
                   "</ul></li>";
     children = $(children).appendTo("#mytree");
    // add the new elements to the treeview
    $("#mytree").treeview({
        add: children
    });
});

最新更新