现在的位置: 首页 > 综合 > 正文

js实现全选与反选

2014年03月17日 ⁄ 综合 ⁄ 共 963字 ⁄ 字号 评论关闭

 function ChkTest(boolValue)  //全选与反选设置,IE可以,FireFox不兼容
{
    var checkAll=document.getElementsByTagName("input");  
    for(var i=0;i<checkAll.length;i++)
    {
        if(checkAll[i].id.indexOf("chkUrlId")!=-1)
        { 
            checkAll[i].checked=boolValue.checked;
       /*     if(boolValue.checked)
            {
                checkAll[i].parentElement.parentElement.style.background="#FFFFFF";//设置背景色的
            }
            else
            {
                checkAll[i].parentElement.parentElement.style.background="";
            }*/
        }
    }
}

//全选与反选设置,兼容IE、FireFox
function selectall(whosform){
    for(var i=0;i<whosform.elements.length;i++){
        var box = whosform.elements[i];
        if (box.name != 'selectAll')
        box.checked = whosform.selectAll.checked;
    }
}

调用function,<input name="selectAll" id="selectAll" type="checkbox" value="" onclick="selectall(this.form)" /><span>全选</span></div><%--ChkTest(this) --%>

Repeater中的多选框:<asp:CheckBox ID="chkUrlId" runat="server"></asp:CheckBox>

 

【上篇】
【下篇】

抱歉!评论已关闭.