//全选反选
//参数:selected:传入this,表示当前点击的组件
//treeMenu:要操作的tree的id;如:id="userTree"
function treeChecked(selected, treeMenu) {
var roots = $('#' + treeMenu).tree('getRoots');//返回tree的所有根节点数组
if (selected.checked) {
for ( var i = 0; i < roots.length; i++) {
var node = $('#' + treeMenu).tree('find', roots[i].id);//查找节点
$('#' + treeMenu).tree('check', node.target);//将得到的节点选中
}
} else {
for ( var i = 0; i < roots.length; i++) {
var node = $('#' + treeMenu).tree('find', roots[i].id);
$('#' + treeMenu).tree('uncheck', node.target);
}
}
}
<input title="全选/反选" type="checkbox" onClick="treeChecked(this,'treeMenu')"/>
- function treeChecked(selected, treeMenu) {
- var roots = $('#' + treeMenu).tree('getRoots');
- if (selected.checked) {
- for ( var i = 0; i < roots.length; i++) {
- var node = $('#' + treeMenu).tree('find', roots[i].id);
- $('#' + treeMenu).tree('check', node.target);
- }
- } else {
- for ( var i = 0; i < roots.length; i++) {
- var node = $('#' + treeMenu).tree('find', roots[i].id);
- $('#' + treeMenu).tree('uncheck', node.target);
- }
- }
- }
- <input title="全选/反选" type="checkbox" onClick="treeChecked(this,'treeMenu')"/>