.Net Treeview Checkboxes - Check All 功能
来源:互联网 发布:linux改变字体大小 编辑:程序博客网 时间:2024/05/20 00:15
目前来看完成Treeview中Checkbox的Check All功能只能自己写Javascript
在Treeview控件中加入onclick="treeViewCheck(event) ;"
下面是我找到的一段JS代码,经实验没有问题。
<script type="text/javascript">
function goDeeperChecked(obj)
{
var chk1 = true;
// Get the parent.
var head1 = obj.parentNode.previousSibling;
// no rows, cant do my work.
if(obj.rows == null)
{
return ;
}
// This is how may rows are at this level.
var pTreeLevel1 = obj.rows[0].cells.length;
// Are we a parentmy ?
if(head1.tagName == "TABLE")
{
// Get the list of rows ahead of us.
var tbls = obj.parentNode.getElementsByTagName("TABLE");
// get the count of that list.
var tblsCount = tbls.length;
// determine if any of the rows underneath are unchecked.
for(i = 0; i < tblsCount; i ++ )
{
var childTreeLevel = tbls[i].rows[0].cells.length;
if(childTreeLevel = pTreeLevel1)
{
var chld = tbls[i].getElementsByTagName("INPUT");
if (chld[0].checked == false)
{
chk1 = false;
break;
}
}
}
var nd = head1.getElementsByTagName("INPUT");
if (nd.length > 0)
{
nd[0].checked = chk1;
}
// do the same for the level above
goDeeperChecked(obj.parentNode);
}
else
{
return;
}
}
function
goDeeper(check, obj)
{
// head1 gets the parent node of the unchecked node
var head = obj.parentNode.previousSibling;
if(head.tagName == "TABLE")
{
// checks for the input tag which consists of checkbox
var matchElement = head.getElementsByTagName("INPUT");
// matchElement1[0] gives us the checkbox and it is unchecked
if (matchElement.length > 0)
{
matchElement[0].checked = false;
}
}
else
{
head = obj.parentNode.previousSibling;
}
if
(head.tagName == "TABLE")
{
goDeeper(check, obj.parentNode);
}
else
{
return
;
}
}
function treeViewCheck(event)
{
// obj gives us the node on which check or uncheck operation has performed
var obj = event.srcElement || event.target ;
var treeNodeFound = false;
var checkedState;
// checking whether obj consists of checkbox to avoid exception
if(obj.tagName == "INPUT" && obj.type == "checkbox")
{
var treeNode = obj;
checkedState = treeNode.checked;
// work our way back to the parent < table > element
do
{
obj = obj.parentNode;
}
while(obj.tagName != "TABLE")
var parentTreeLevel = obj.rows[0].cells.length;
var parentTreeNode = obj.rows[0].cells[0];
// get all the TreeNodes inside the TreeView (the parent < div > )
var tables = obj.parentNode.getElementsByTagName("TABLE");
// checking for any node is checked or unchecked during operation
if(obj.tagName == "TABLE")
{
// if any node is unchecked then their parent node are unchecked
if( !treeNode.checked )
{
goDeeper(false, obj);
}
// end if - unchecked
// total number of TreeNodes
var numTables = tables.length
if(numTables >= 1)
{
// cycle through all the TreeNodes
// until we find the TreeNode we checked
for
(i = 0;
i < numTables;
i ++ )
{
if(tables[i] == obj)
{
treeNodeFound = true;
i ++ ;
if(i == numTables)
{
// if we're on the last TreeNode, we are done
break;
}
}
if(treeNodeFound == true)
{
var childTreeLevel = tables[i].rows[0].cells.length;
if(childTreeLevel > parentTreeLevel)
{
var
cell = tables[i].rows[0].cells[childTreeLevel - 1];
// set the checkbox to match the checkedState
var inputs = cell.getElementsByTagName("INPUT");
inputs[0].checked = checkedState;
}
else
{
// if any of the preceding TreeNodes are not deeper stop
break;
}
}
// end if
}
// end for
}
// end if - numTables >= 1
// if all child nodes are checked then their parent node is checked
if(treeNode.checked)
{
goDeeperChecked(obj);
}
// end if - checked
}
// end if - tagName = TABLE
}
// end if
}
// end function
</script>
- .Net Treeview Checkboxes - Check All 功能
- ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript
- ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript
- Check/Uncheck All Checkboxes in Asp.Net Gridview
- Check/Un-Check checkboxes items in ASP.NET DataGrid using JavaScript
- Check/Uncheck checkboxes in GridView using JavaScript
- check all
- PB中treeview 的checkboxes用法完整版
- PB中treeview 的checkboxes用法完整版
- PB中treeview 的checkboxes用法完整版
- Checkboxes
- js check all checkbox
- Checkboxes Beside Labels in ASP.Net MVC4
- treeview中check复选事件
- Csharp: Treeview check list value
- Csharp: Treeview check list value
- ASP.NET 2.0 TreeView中用JavaScript实现单选功能.
- 增加TREEVIEW(ASP.NET)前台级连选择功能
- 转:感恩节感言
- wget下载页面
- 企业管理软件的“渐进式实施方法”
- dos命令总集
- ORA-00942:table or view does not exist
- .Net Treeview Checkboxes - Check All 功能
- 几大ERP软件实施方法与过程 (转)
- 如何启动或关闭数据库的归档(ARCHIVELOG)模式
- 如何杜绝iframe挂马
- 给GridView加点料:Div动态浮动显示
- translation
- 安装VMware Workstation
- ASP.NET2.0 Ajax的简单配置与应用
- 异端辩解