我的一个gridview控件每一列都是TemplateField,某一列TemplateField用的是checkboxlist.其他列用的是TextBox,除此之外,页面还用到了模板页,所以,生成的页面里边有下面的代码
<table id="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox" border="0"> <tr><td><input id="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox_0" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView1$ctl02$choicesCheckBox$0" /><label for="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox_0">取消</label></td><td><input id="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox_1" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView1$ctl02$choicesCheckBox$1" /><label for="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox_1">减少</label></td>
</tr>
</table>
        </td><td>
                    <span id="ctl00_ContentPlaceHolder1_GridView1_ctl02_IDLabel" style="display:inline-block;width:30px;position: relative">931149</span>
                </td><td>
     <input name="ctl00$ContentPlaceHolder1$GridView1$ctl02$S_TextBox" type="text" value="0" id="ctl00_ContentPlaceHolder1_GridView1_ctl02_S_TextBox" style="width:30px;position: relative" />
                </td>
现在需要在客户端使用Javascript脚本实现全选功能,如何实现不通过getelementbyname 跟getelementbyid的方法来区分生成的所有html<input>标签。

解决方案 »

  1.   


    <td> 
    <table id="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox" border="0"> <tr> 
    <td> 
    <input id="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox_0" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView1$ctl02$choicesCheckBox$0" /> 
    <label for="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox_0">取消 </label> </td> 
    <td> 
    <input id="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox_1" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView1$ctl02$choicesCheckBox$1" /> 
    <label for="ctl00_ContentPlaceHolder1_GridView1_ctl02_choicesCheckBox_1">减少 </label> </td> 
    </tr></table> </td> 
    <td>
    <span id="ctl00_ContentPlaceHolder1_GridView1_ctl02_IDLabel" style="display:inline-block;width:30px;position: relative">931149 </span></td> 
    <td> 
        <input name="ctl00$ContentPlaceHolder1$GridView1$ctl02$S_TextBox" type="text" value="0" id="ctl00_ContentPlaceHolder1_GridView1_ctl02_S_TextBox" style="width:30px;position: relative"  /></td><p>
    <p>
    <a id="check_all" href="###" onclick="checkAll(this)"> 全选</a><script language="javascript">
    <!--
    function checkAll(_this){
    var t=_this.name=="all_check"?0:1
    var obj=document.getElementsByTagName("input")
    for (var i=0;i<obj.length;i++){
    if (obj[i].type=="checkbox")obj[i].checked=t
    }
    _this.name=_this.name=="all_check"?"all_no_check":"all_check"
    _this.innerHTML=_this.name=="all_check"?"全不选":"全选"

    }
    //-->
    </script>