//点击空白处隐藏树 文档冒泡
<!-- javascript -->
$(document).bind('click',function(e){
$("#tree").css("display", "none");
});
//阻止冒泡
$('#treeDiv').bind('click',function(e){
e.stopPropagation();
showTree();
});
//阻止冒泡
$('#tree').bind('click',function(e){
e.stopPropagation();
});
<!-- jsp -->
<div id="treeDiv" style="width:120px;" class="btn-group" tabIndex="1111">
<button style="width:120px;" class="btn btn-success dropdown-toggle" > 主机来源
<span class="caret"></span>
</button>
<ul id="tree" status="show" class="dropdown-menu ztree"
style="display: none;">
</ul>
</div>
<!-- javascript -->
$(document).bind('click',function(e){
$("#tree").css("display", "none");
});
//阻止冒泡
$('#treeDiv').bind('click',function(e){
e.stopPropagation();
showTree();
});
//阻止冒泡
$('#tree').bind('click',function(e){
e.stopPropagation();
});
<!-- jsp -->
<div id="treeDiv" style="width:120px;" class="btn-group" tabIndex="1111">
<button style="width:120px;" class="btn btn-success dropdown-toggle" > 主机来源
<span class="caret"></span>
</button>
<ul id="tree" status="show" class="dropdown-menu ztree"
style="display: none;">
</ul>
</div>
该博客主要围绕文档冒泡和阻止冒泡展开。通过JavaScript代码实现点击空白处隐藏树菜单,同时在特定元素上绑定事件并使用e.stopPropagation()方法阻止冒泡。还给出了JSP代码,包含树菜单的HTML结构。
1053

被折叠的 条评论
为什么被折叠?



