我在使用d3选择检查和取消选中复选框时遇到困难.以下代码似乎不起作用.我希望在按下'check'时检查所有复选框,并在按下'uncheck'时取消选中所有复选框.
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<button type='button' onclick='checkAll()'>Check</button>
<button type='button' onclick='uncheckAll()'>Uncheck</button>
<script src="http://d3js.org/d3.v2.min.js?2.10.0"></script>
<script>
function checkAll(){
d3.selectAll('input').attr('checked','true');
}
function uncheckAll(){
d3.selectAll('input').attr('checked','false');
}
</script>
</body>
Run Code Online (Sandbox Code Playgroud)