原生js循环获取表格中input的值
2021-03-29 01:26
标签:代码 ntb element one center 清单 getattr NPU disabled css代码清单: 原生js循环获取表格中input的值 标签:代码 ntb element one center 清单 getattr NPU disabled 原文地址:https://www.cnblogs.com/qianxunpu/p/12611681.html table>
tbody class="tbody" id="pileListItemDesc">
tr class="text-center lastTr">
td class="index">4td>
td class="depth">input type="text" name="depth" class="input-none input-disabled" value="1.2"
disabled="">td>
td class="hammerValue">input type="text" name="hammerValue" class="input-zt" value="18">td>
td class="correctValue">
input type="text" name="correctValue" class="input-zt" ignore="ignore" value="">
td>
td class="description">input type="text" name="description" class="input-zt" value="-">td>
td class="remark">input type="text" name="remark" class="input-zt" value="-">td>
td>td>
tr>
tr class="text-center">
td class="index">3td>
td class="depth">input type="text" name="depth" class="input-none input-disabled" value="0.9"
disabled="">td>
td class="hammerValue">input type="text" name="hammerValue" class="input-zt" value="14">td>
td class="correctValue">
input type="text" name="correctValue" class="input-zt" ignore="ignore" value="">
td>
td class="description">input type="text" name="description" class="input-zt" value="-">td>
td class="remark">input type="text" name="remark" class="input-zt" value="-">td>
td>td>
tr>
tbody>
table>
var tbody = document.getElementById("pileListItemDesc");
var rows = tbody.rows; //获取行
var depthList = [];
for (var i = 0; i {
var obj = {};
var cells = rows[i].cells; //获取列
for (var j = 0; j {
var input = cells[j].getElementsByTagName("input");
if (input.length == 0) {
if (cells[j].getAttribute(‘class‘) === ‘index‘) {//获取index的值
obj["index"] = cells[j].innerText
}
} else {
var val = input[0].value;
var name = input[0].name;
obj[name] = val;
}
}
depthList.push(obj);
}
console.log(depthList)
文章标题:原生js循环获取表格中input的值
文章链接:http://soscw.com/index.php/essay/69302.html