您好,欢迎来到图奈娱乐。
搜索
您的当前位置:首页js获取GridView中行数据的两种方法分享_javascript技巧

js获取GridView中行数据的两种方法分享_javascript技巧

来源:图奈娱乐


第一种方法:
代码如下:
function submitData() {
var tb = document.getElementById(IDArray[0]); //获取服务器控件GridView的ID
if (tb)
{
var rows = tb.rows;
for (var i = 1; i < rows.length; i++) {
var id = rows[i].cells[1].innerText;
var name = rows[i].cells[2].innerHTML;
var oDropDownList = rows[i].cells[3].childNodes[0];
var oText = oDropDownList.options[oDropDownList.selectedIndex].text; //获取GridView中下拉列表中选中的文本
var oValue = oDropDownList.options[oDropDownList.selectedIndex].value;; //获取GridView中下拉列表中选中的值
}
}
}

第二种方法:
代码如下:
function submitData() {
var tb = document.getElementById(IDArray[0]);
if (tb.hasChildNodes) {
if (tb.childNodes[0] != null) {
var rowCount = tb.childNodes[0].childNodes.length;
for (var i = 1; i < rowCount; i++) {
var child = tb.childNodes[0].childNodes[i];
var id = rowCount[i].cells[1].innerHTML;
var name = child.childNodes[1].innerHTML;
var oDropDownList = child.childNodes[2].childNodes[0];
var oText = oDropDownList.options[oDropDownList.selectedIndex].text;
var oValue = oDropDownList.options[oDropDownList.selectedIndex].value
}
}
}

Copyright © 2019- tnml.cn 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务