<div id="1">
<div id="1_1" style="display: block;"> 我是子項目一</div>
<div id="1_2" style="display: block;"> 我是子項目二</div>
</div>
<input id="checkGetFirstData" type="checkbox" onclick="CheckGetData(this)"/>
<script>
function CheckGetData(obj)
{
var tree = document.getElementById("1");
var treendes = tree.childNodes;
for(i=0; i <treendes.length; i++)
{
if(treendes[i].nodeType==1 && treendes[i].tagName)
{
if(obj.checked)
{
tree.childNodes[i].style.display="none";
}
else
{
tree.childNodes[i].style.display="";
//tree.childNodes[1].style.display="block";
}
}
}
}
</script>
//下面就可以測試用TreeView模擬點擊打開及關閉
function expand(obj,closestr,openstr,treeid) {
var treeobj = document.getElementById(treeid);
var check = (obj.value.indexOf('展開') != -1) ? "Expand" : "Collapse";
obj.value = (obj.value != openstr) ? openstr : closestr;
for (var i = 0; i < treeobj.childNodes.length; i++) {
if (treeobj.childNodes[i] != null && treeobj.childNodes[i].id) {
TreeNodeExpand(document.getElementById(treeobj.childNodes[i].id), check);
}
}
}
//展開或折曡子節點
function TreeNodeExpand(elm, check) {
for (var i = 0; i <= elm.childNodes.length; i++) {
var child = elm.childNodes[i];
if (child != null) {
arguments.callee(child, check);
if (child.id != null && child.id != "" && child.getAttribute('href') && child.firstChild.tagName == 'IMG') {
if (child.firstChild.getAttribute('alt').indexOf(check) != -1) {
eval(child.getAttribute('href').replace('javascript:', ''));
//window.location = child.getAttribute('href');
}
}
}
}
}
Ps另外有可能FF會多判定→if (nodes[i].nodeType == 1 && nodes[i].tagName )子群組加上這個就可以看到正確
沒有留言:
張貼留言