如何勾选属于GridVIew的复选框?
How Can I Check the checkbox that belongs a GridVIew?
我想做一个javascript函数,检查未选中的复选框。我现在的功能是选中所有未选中的复选框,我需要选中特定的GridView未选中的复选框
function checar() {
var el = document.getElementsByTagName("input");
for (var i = 0; i < el.length; i++) {
if (el[i].type == "checkbox") {
el[i].checked = true;
}
}
}
首先要限制元素的搜索范围。一种方法是使用getElementById
function checar() {
var grd = document.getElementById("<%=grd.ClientID%>"); // <-- Add this line
var el = grd.getElementsByTagName("input"); // <-- change the scope of this to grd
//rest of your code here.
}
示例使用div,但你会得到的想法,我认为:http://jsfiddle.net/8LRkk/
编辑包括设置特定的网格ID。
要获取特定gridview的所有复选框,您需要抓取其ClientID
包含gridview的ClientID
部分的复选框,因为所有控件都有一个id为"堆叠"。
你的函数应该作为一个基础,它只需要有一个额外的检查:
function checar() {
var el = document.getElementsByTagName("input");
// Get the client id of the gridview from ASP here
var gvID = '<%= this.myGridview.ClientID %>';
for (var i = 0; i < el.length; i++) {
// Call the id of the checkbox and check to see if it
// contains the client id of the gridview at the same time
if (el[i].type == "checkbox" && el.id.indexOf(gvID) != -1) {
el[i].checked = true;
}
}
}
相关文章:
- 如何使用javascript函数在gridview中按行启用/禁用复选框
- 在GridView中,当单击复选框时,在网格的同一行中使用JavaScript将标签中的值添加到TextBox
- 使用Jquery查找asp.net GridView中的所有复选框
- 复选框一次选中一个不在gridview中工作
- 如何禁用和启用删除按钮,如果未在 GridView 中选中复选框由 Jquery
- 使用javascript函数在chrome和firefox中不起作用的gridview行中应至少选中一个复选框
- c#中gridview中的复选框
- 勾选所有复选框在gridview中勾选所有复选框花费很长时间
- Gridview中复选框背后的Javascript函数
- Asp.net多个gridview, headertemplate中的复选框选择所有/取消选择所有功能
- 选中gridview中所有行的特定列的所有复选框
- GridView Header复选框更改在ie9中不工作
- 如何使用JavaScript在GridView中启用和禁用复选框
- 在gridview中只选择一个复选框,然后编辑选中的行
- 如何计数选中的复选框,不包括标题,在asp.net gridview中使用javascript
- 如何使用javascript将gridview中的复选框值转换为文本框
- 必应地图图钉处理gridview复选框
- 使用JavaScript在同一个GridView中启用或禁用复选框更改事件的文本框
- 如何勾选属于GridVIew的复选框?
- Javascript选择gridview中的所有复选框