100分请人帮我组织一句JavaScript
function btnInverse_onclick()
{
for (var i = 2; i <=20; i++)
{
var parameter = "gvSystemAlarmManage_ctl0 " + i + "_ccbSelect ";
var ccbSelect = document.getElementById(parameter);
if (null != ccbSelect)
{
if (ccbSelect.checked)
{
ccbSelect.checked = false;
}
else
{
ccbSelect.checked = true;
}
}
}
}
原先我是 "gvSystemAlarmManage_ctl0 " + i + "_ccbSelect "这样得到GridView中各个复选框ID的然后在进行其他操作,但是现在我这个页面要做成用户控件了,为了得到控件的ID我不得不采用 " <%=控件ID.ClientID%> "这中形式。
现在的问题是我组织不好这句话了,就是把控件ID为 "gvSystemAlarmManage_ctl0 " + i + "_ccbSelect "放到这种形式 " <%=控件ID.ClientID%> "里面。
------解决方案--------------------反选?
try ->
function btnInverse_onclick()
{
var grd = document.getElementById( ' <% GridView.ClientID %> ');
var sltArr = grd.getElementsByTagName( "input ");
for (var i = 0; i <= sltArr.length; i++) {
if(sltArr[i].type == "checkbox " && sltArr[i].id.indexOf( "ccbSelect ") > -1) {
sltArr[i].checked = !sltArr[i].checked;
}
}
}
------解决方案-------------------- <script>
function test(i)
{
var s = document.getElementById( "table1 ");
var x = s.getElementsByTagName( "input ");
var selAll = document.getElementById( "selAll ");
for(item=0;item <x.length;item++)
{
if(x[item].id.substring(0,4)== "aaa_ ")
{
if(i==1)
x[item].checked = selAll.checked;
else
x[item].checked = !x[item].checked;
}
}
}
</script>
<table id= "table1 ">
<tr>
<td> <input type= "checkbox " id= "aaa_1 "/> </td> <td> <input type= "text " id= "bbb_1 " value= "1 "/> </td>
</tr>
<tr>
<td> <input type= "checkbox " id= "aaa_2 "/> </td> <td> <input type= "text " id= "bbb_2