我需要获取gridviewrow中3个隐藏字段的值,其中复选框已被选中&与他们建立查询字符串。 我只能使用Javascript,不可能在我们的框架中使用回传:s 有什么想法?得到一个HTML表格中3个隐藏字段的值,其中复选框已被选中
感谢
我需要获取gridviewrow中3个隐藏字段的值,其中复选框已被选中&与他们建立查询字符串。 我只能使用Javascript,不可能在我们的框架中使用回传:s 有什么想法?得到一个HTML表格中3个隐藏字段的值,其中复选框已被选中
感谢
如果你是使用jQuery在你的框架只是使用jQuery.getJSON()更新状态
这可能是更容易,它似乎。
首先让我们得到到GridView(呈现为一个表)
var t = document.getElementById('<% =GridView1.ClientID %>'); // use your gridview's id
参考然后我们需要一个复选框列表
var tableInputs = t.getElementsByTagName('input'); // gets all input elements within the table
var chkList = []; // array where we'll keep track of marked checkboxes
for(var i=0; i<tableInputs.length; i++) {
// see if it's a checkbox and whether or not it's checked
if (tableInputs[i].type.match(/checkbox/i) && tableInputs[i].checked) {
// it is and it is, so add it to the list
chkList.push(tableInputs[i]);
}
}
现在你可以使用复选框来获得参考到特定的行并找到隐藏的元素
var fields;
var tr = null;
for (var j = 0; j < chkList.length; j++) {
// look up the heirarchy until you find the table row
tr = chkList[j].parentNode;
while (!tr.nodeName.match(/tr/i)) {
tr = chkList[j].parentNode;
}
// repeat the checkbox process for hidden fields
fields = tr.getElementsByTagName('input'); // all inputs in the same row
for (var k = 0; k < fields.length; k++) {
// see if it's a hidden field
if (fields[k].type.match(/hidden/i)) {
//TODO: here's a hidden field, do something
}
}
tr = null;
}
我并不总是记得标记nam es区分大小写,所以我默认为不区分大小写的正则表达式。
如果您正在使用jQuery
var values = [];
$.each($("#gridid .hiddenfields"), function(i, item) {
values.push($(item).val());
});
这将让你与数组中的值,也隐藏字段必须是类=“hiddenfields”,希望这有助于。
+1对于非jQuery的答案。非常感谢! – 2011-05-16 03:31:20