jstree 的复选框插件在选中/取消选中节点时似乎确实执行了其他操作。我相信以下内容应该可以满足您的需求:
$(function(){
// Initialize jstree
var $tree = $('.tree-target').jstree({
"plugins": ["checkbox"]
});
// Bind an event to the anchor tag within each tree entry
// Note: '.on' is used here as this will ensure that any
// dynamically-generated entries will also use this 'click'
// event.
$tree.on('click', 'li.tree > a', function (e) {
e.stopPropagation();
// Find the first parent 'tree' element
var $node = $(this).parents('li.tree').eq(0);
// Toggle the state of the current 'tree' element
// Note: The third parameter (in this case 'toggle')
// can be any value other than true or false
$tree.jstree('change_state', $node, 'toggle');
return false;
});
});
在旁注中,我认为您的方法导致显着延迟的原因可能与您将click
事件绑定到页面上的每个<a/>
标签有关。当试图找到适当的事件目标时,这将导致大量开销。