请问我怎样实现选项“查看”“修改”“删除”都选中的情况下,自动勾选“全选”,相反则去掉全选~~?(全选及取消全选已实现)代码如下:
function checkAll(id,flag){
var check=$("#"+id+" input[type='checkbox']"); //“全选”chekbox选项对象
var ifAll=$("#"+flag); //“table11”chekbox选项对象
check.attr("checked",ifAll.attr("checked"));
}
<table id="table">
<tr><td><input type="checkbox" id="ifAll" onclick="checkAll('table','ifAll')"/>全选</td></tr>
<tr>
<td><input type="checkbox" id="ifAll_1" onclick="checkAll('table_1','ifAll_1')"/>全选1</td>
<td>
<table id="table_1">
<tr>
<td><input type="checkbox" name="a" value="0"/>查看</td>
<td><input type="checkbox" name="a" value="2"/>修改</td>
<td><input type="checkbox" name="a" value="3"/>删除</td>
</tr>
</table>
</td>
</tr><tr>
<td><input type="checkbox" id="ifAll12" onclick="checkAll('table_2','ifAll_2')"/>全选2</td>
<td>
<table id="table_2">
<tr>
<td><input type="checkbox" name="b" value="0"/>查看</td>
<td><input type="checkbox" name="b" value="2"/>修改</td>
<td><input type="checkbox" name="b" value="3"/>删除</td>
</tr>
</table>
</td>
</tr>
</table>
function checkAll(id,flag){
var check=$("#"+id+" input[type='checkbox']"); //“全选”chekbox选项对象
var ifAll=$("#"+flag); //“table11”chekbox选项对象
check.attr("checked",ifAll.attr("checked"));
}
<table id="table">
<tr><td><input type="checkbox" id="ifAll" onclick="checkAll('table','ifAll')"/>全选</td></tr>
<tr>
<td><input type="checkbox" id="ifAll_1" onclick="checkAll('table_1','ifAll_1')"/>全选1</td>
<td>
<table id="table_1">
<tr>
<td><input type="checkbox" name="a" value="0"/>查看</td>
<td><input type="checkbox" name="a" value="2"/>修改</td>
<td><input type="checkbox" name="a" value="3"/>删除</td>
</tr>
</table>
</td>
</tr><tr>
<td><input type="checkbox" id="ifAll12" onclick="checkAll('table_2','ifAll_2')"/>全选2</td>
<td>
<table id="table_2">
<tr>
<td><input type="checkbox" name="b" value="0"/>查看</td>
<td><input type="checkbox" name="b" value="2"/>修改</td>
<td><input type="checkbox" name="b" value="3"/>删除</td>
</tr>
</table>
</td>
</tr>
</table>
click时只有这些都选中时才让全选选中。
{
var tab =ch.parentElement.parentElement.parentElement;
var j= ch.parentElement.cellIndex;
// var tab=document.getElementById("table_1");
for(var i=1;i<tab.rows.length;i++)
{
var objCheckBox=tab.rows[i].cells[j].firstChild;
if(objCheckBox.checked!=null)
objCheckBox.checked = ch.checked;
}
}
$("#checkall").click(function(){
if($(this).get(0).checked){
$("input[name='cb']").attr("checked",true);
}
else{}
})