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