我正在尝试为多个复选框实现切换,但如果我手动切换一个,则切换不再考虑该复选框。
var publishAll = $("toggle");
publishAll.observe('click', function(e){
var state = null;
if(this.checked) {
state = "checked";
}
$$('.checkbox').invoke('writeAttribute', 'checked', state);
});
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
<input id="toggle" type="checkbox" name="toggle" value="true"> Toggle checkbox<br /><br />
check these manually and it won't work with toggle anymore.<br />
<input class="checkbox" type="checkbox" name="checkbox[]" value="1"><br />
<input class="checkbox" type="checkbox" name="checkbox[]" value="2">
我做错了什么吗?