GridView checkbox' all and cancel 'perfectly compatible with IE and Firefox
- 2020-07-21 07:22:33
- OfStack
function selectAll(obj)
{
var theTable = obj.parentNode.parentNode.parentNode.parentNode;
var i;
var j = obj.parentNode.cellIndex;
for(i=1;i<theTable.rows.length;i++)
{
if(theTable.rows[i].cells.length<j) continue;
var objCheckBox = theTable.rows[i].cells[j].getElementsByTagName('input')[0];
if(objCheckBox.checked!=null)objCheckBox.checked = obj.checked;
}
}
Add onclick="selectAll(this)" to checkbox of Head to support as many columns as you want.
<asp:TemplateField HeaderText="<input id='Checkbox1' type='checkbox' onclick='selectAll(this)' /> The serial number ">
<ItemTemplate>
<input id="Checkbox1" type="checkbox" onclick="Get_jdzh(this);" title='<%#Convert.ToString(Eval("cpdm")).Trim() %>' />
</ItemTemplate>
</asp:TemplateField>
theTable. rows [i] cells [j] getElementsByTagName (' input) [0]; Never use firstChild, otherwise you will make an error under FF.