CheckBox选中后点击画面其他地方自动取消选中

小苹果1 发布于 2017/11/30 13:10
阅读 136
收藏 0

@zTree 你好,想跟你请教个问题:

上代码: var setting = {
check : {
enable : true,
chkboxType: {"Y":"", "N":""}
},
view: {
dblClickExpand: false
},
data : {
simpleData : {
enable : true
}
},
callback : {
beforeClick: beforeClick,
onCheck: onCheck,
//点击文字勾选复选框
onClick : function(e, treeId, treeNode, clickFlag) {
$.fn.zTree.getZTreeObj("treeDemo").checkNode(treeNode,
!treeNode.checked, true);

if ($("#treeDiv").css("display") == "block") {
if (nodes.isParent) {
$("body").bind("mousedown", onBodyDown);
} else {
$("#treeDiv").css("display", "none");
}
} else {
$("#treeDiv").slideDown("fast");
//$("#treeDiv").css("display","block");
}

}
}
}, zTree;

var code;
var zNodes = [ {
id : 11,
pId : 1,
name : "T1站",
open : true
}, {
id : 12,
pId : 1,
name : "T2站",
open : true
}, {
id : 13,
pId : 1,
name : "T3站",
open : true
}, {
id : 14,
pId : 1,
name : "LNG站",
open : true
}, {
id : 15,
pId : 1,
name : "RTU站",
open : true
} ];

function beforeClick(treeId, treeNode) {
debugger;
var zTree = $.fn.zTree.getZTreeObj("treeDemo");
zTree.checkNode(treeNode, !treeNode.checked, null, true);
return false;
}
function onCheck(e, treeId, treeNode) {
debugger;
var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
nodes = zTree.getCheckedNodes(true),
v = "";
for (var i=0, l=nodes.length; i<l; i++) {
v += nodes[i].name + ",";
}
if (v.length > 0 ) v = v.substring(0, v.length-1);
document.getElementById("zTree").value = v;
}
function treeDisplay() {
//弹出标签
var cityObj = $("#zTree");
var cityOffset = $("#zTree").offset();
$("#treeDiv").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

$("body").bind("mousedown", onBodyDown);

$.fn.zTree.init($("#treeDemo"), setting, zNodes);


function onBodyDown(event) {
debugger;
if (!(event.target.id == "zTree" || event.target.id == "treeDiv" || $(
event.target).parents("#treeDiv").length > 0)) {
//$("#treeDiv").css("display", "none");
hideMenu();
}
}
function hideMenu() {
$("#treeDiv").fadeOut("fast");
$("body").unbind("mousedown", onBodyDown);
}

 

加载中
返回顶部
顶部