Javascript->;选中/取消选中gridview';基于中继器的s复选框(ChildCheckbox)';s复选框(父复选框)
我在下面有一个javascript函数——事实上,我在一个转发器中有一个复选框,在这个转发器中有一个gridview,它也有一些复选框 我想根据repeater复选框的选择启用或禁用GridView复选框 因此,我在itemsRepeater_ItemDataBound上注册了一个JavaScript。要捕获中继器->的-Which复选框(RepeaterCheckBoxId)和Which GridView(Grid),如下所示 功能启用禁用(RepeaterCheckboxid,网格) {Javascript->;选中/取消选中gridview';基于中继器的s复选框(ChildCheckbox)';s复选框(父复选框),javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我在下面有一个javascript函数——事实上,我在一个转发器中有一个复选框,在这个转发器中有一个gridview,它也有一些复选框 我想根据repeater复选框的选择启用或禁用GridView复选框 因此,我在itemsRepeater_ItemDataBound上注册了一个JavaScript。要捕获中继器->的-Which复选框(RepeaterCheckBoxId)和Which GridView(Grid),如下所示 功能启用禁用(RepeaterCheckboxid,网格) { v
var grid=document.getElementById(网格);
if(grid==null)
返回;
//变量以包含网格的单元格
var细胞;
如果(grid.rows.length>0){
//循环从1开始。行[0]指向标题。
对于(i=1;i
但我观察到启用禁用工作正常,但选中未选中则不工作。
如果中继器的复选框未选中,如何取消选中gridview中的所有复选框
如果你们有什么想法,请帮帮我。试试这样:
cell = grid.rows[i].cells[1];
var checkedAttrib = document.createAttribute('checked');
checkedAttrib.value = document.getElementById(RepeaterCheckboxid).checked; // this will take the value from 'RepeaterCheckboxid'
cell.childNodes[0].setAttributeNode(checkedAttrib);
尝试使用JQuery:
$.each($(grid).find("tr"),function(){
var chk = $(this).find("td:first").find(":checkbox");
chk.attr("checked",$("#"+RepeaterCheckboxid).attr("checked"));
chk.attr("disabled",!$("#"+RepeaterCheckboxid).attr("checked"));
});
您可能需要使用gridview的客户端ID访问gridview,如:
$('#<%=GridView1.ClientID %>')
$(“#”)
要获取gridview中的所有复选框,可以使用.find(“输入:复选框”)和遍历每个复选框:
<script type="text/javascript">
function CheckUnCheckAll(chk) {
$('#<%=GridView1.ClientID %>').find("input:checkbox").each(function () {
if (this != chk) {
this.checked = chk.checked;
}
});
}
</script>
功能检查取消勾选(chk){
$('#')。查找(“输入:复选框”)。每个(函数(){
如果(此!=chk){
this.checked=chk.checked;
}
});
}
使用其对象调用CheckUnCheckAll(this)on header复选框
检查此处的示例:
<script type="text/javascript">
function CheckUnCheckAll(chk) {
$('#<%=GridView1.ClientID %>').find("input:checkbox").each(function () {
if (this != chk) {
this.checked = chk.checked;
}
});
}
</script>