思路就是:找出父節點的所有子節點的checked的屬性設定成與父節點一致即可
我是利用jquery實現,看看是否符合你的要求
<scriptsrc="../lib/jquery.js"type="text/javascript"></script>
<scriptsrc="../jquery.treeview.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(function(){
$("#tree").treeview();
$("input[name="ids"]").click(function(){
varcheckedValue=this.checked;
$(this).parent("li").find("input[name="ids"]").attr("checked",checkedValue);
});
})
</script>
<ulid="tree">
<li>
<inputtype="checkbox"name="ids"id="test"/>
<spanclass="folder">test1</span>
<ul>
<inputtype="checkbox"name="ids"/>
<spanclass="folder">test11</span>
</li>
</ul>
<spanclass="folder">test12</span>
<spanclass="folder">test121</span>
思路就是:找出父節點的所有子節點的checked的屬性設定成與父節點一致即可
我是利用jquery實現,看看是否符合你的要求
<scriptsrc="../lib/jquery.js"type="text/javascript"></script>
<scriptsrc="../jquery.treeview.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(function(){
$("#tree").treeview();
$("input[name="ids"]").click(function(){
varcheckedValue=this.checked;
$(this).parent("li").find("input[name="ids"]").attr("checked",checkedValue);
});
})
</script>
<ulid="tree">
<li>
<inputtype="checkbox"name="ids"id="test"/>
<spanclass="folder">test1</span>
<ul>
<li>
<inputtype="checkbox"name="ids"/>
<spanclass="folder">test11</span>
</li>
</ul>
<ul>
<li>
<inputtype="checkbox"name="ids"/>
<spanclass="folder">test12</span>
<ul>
<li>
<inputtype="checkbox"name="ids"/>
<spanclass="folder">test121</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>