想要实现点击节点内容的同时,展开或者关闭子节点。看了bootstrap treeview文档,发现没有关于各节点的点击事件,只有选中和取消选中事件。
解决方案:想给各个<li>绑定点击事件,点击<li>的同时,触发点击加号或者减号,代码如下
<script>
$(function(){
$('#tree').on('click','li',function(){
if($(event.target).children(".glyphicon").hasClass("glyphicon-plus") || $(event.target).children(".glyphicon").hasClass("glyphicon-minus")){
$(event.target).children(".glyphicon")[0].click();
}
});
})
</script>