SearchDesignPatent.treeContainer().jstree({ 'core' : { 'data' : json.data }, }).bind('click.jstree', function(event) { var eventNodeName = event.target.nodeName; if (eventNodeName == 'INS') { return; } else if (eventNodeName == 'A') { var $subject = $(event.target).parent(); //有Bug,非葉子節點未展開前,下面條件也成立 if ($subject.find('ul').length > 0){ alert("請選擇葉子節點"); } else { if(window.console){ console.log($subject.text()); console.log($subject.attr("id")); console.log($("input[name='type']").val()); $("input[name='type']").val($subject.attr("id")); } } } }).on('changed.jstree', function(e, data) { r = []; var i, j; for (i = 0, j = data.selected.length; i < j; i++) { var node = data.instance.get_node(data.selected[i]); if (data.instance.is_leaf(node)) { r.push(node.id); alert("葉子"); }else{ alert("節點"); } } });