//方法一
function checkAll(){
var chkStatus = document.getElementsByName("option"); "option"为需要全选的name
for(i=0;i<chkStatus.length;i++) {
chkStatus[i].checked = event.srcElement.checked;
}
}
<input type='checkbox' name='option'>全选
//方法二
<script type="text/javascript">
$(document).ready(function(){
//全选||取消
$('#chooseAllCheck').toggle(function(){
$("input[name='titles']").each(function(){
$(this).attr('checked',true);
});
$(this).attr('value',"反选");
},function(){
$("input[name='titles']").each(function(){
$(this).attr('checked',false);
});
$(this).attr('value',"全选");
}
)
});
</script>
<input type="button" id="chooseAllCheck" value="全选"/>
<div>
<div style="width : 400px; line-height: 2.0; font-size: 12px; color: #444; margin: 10px 0 5px 30px;">
<table>
<tr>
<td><input style="margin-right: 5px;" type="checkbox" name="titles" id="1" value="1" alt=""/></td>
<td><input style="margin-right: 5px;" type="checkbox" name="titles" id="2" value="2" alt=""/></td>
<td><input style="margin-right: 5px;" type="checkbox" name="titles" id="3" value="3" alt=""/></td>
<td><input style="margin-right: 5px;" type="checkbox" name="titles" id="4" value="4" alt=""/></td>
</tr>
</table>
</div>
</div>
function checkAll(){
var chkStatus = document.getElementsByName("option"); "option"为需要全选的name
for(i=0;i<chkStatus.length;i++) {
chkStatus[i].checked = event.srcElement.checked;
}
}
<input type='checkbox' name='option'>全选
//方法二
<script type="text/javascript">
$(document).ready(function(){
//全选||取消
$('#chooseAllCheck').toggle(function(){
$("input[name='titles']").each(function(){
$(this).attr('checked',true);
});
$(this).attr('value',"反选");
},function(){
$("input[name='titles']").each(function(){
$(this).attr('checked',false);
});
$(this).attr('value',"全选");
}
)
});
</script>
<input type="button" id="chooseAllCheck" value="全选"/>
<div>
<div style="width : 400px; line-height: 2.0; font-size: 12px; color: #444; margin: 10px 0 5px 30px;">
<table>
<tr>
<td><input style="margin-right: 5px;" type="checkbox" name="titles" id="1" value="1" alt=""/></td>
<td><input style="margin-right: 5px;" type="checkbox" name="titles" id="2" value="2" alt=""/></td>
<td><input style="margin-right: 5px;" type="checkbox" name="titles" id="3" value="3" alt=""/></td>
<td><input style="margin-right: 5px;" type="checkbox" name="titles" id="4" value="4" alt=""/></td>
</tr>
</table>
</div>
</div>