本节内容:
jquery遍历Table表头。
例子:
复制代码 代码示例:
/**
* 遍历table的表头
* 编辑:www.jb200.com
*/
function CheckTotal(textBoxObj)
{
var trNode = textBoxObj.parent().parent(); //获取input的“爷爷”--tr
var totalIdex = 0;
var standardpackIndex = 0;
var availableIndex = 0;
var remarksIndex = 0;
$("#dgItem").find('th').each(function (thindex, thitem) { //遍历Table dgItem的th
var headCaption = $(thitem).text();
if (headCaption == "Standard Pack") {
standardpackIndex = thindex;
}
if (headCaption == "Total") {
totalIdex = thindex;
}
if (headCaption == "Available") {
availableIndex = thindex;
}
if (headCaption == "Remarks") {
remarksIndex = thindex;
}
});
var total = 0;
for (var j = standardpackIndex + 1; j < totalIdex; j++) {
var textBox = trNode.children().eq(j).children();
if (!isNaN(textBox.val()) && textBox.val() != "") {
total += parseInt(textBox.val());
}
else {
total += 0;
}
}
if (total != 0) {
trNode.children().eq(totalIdex).children().val(total);
}
else {
trNode.children().eq(totalIdex).children().val("");
}
var availableQty = parseInt(trNode.children().eq(availableIndex).text());
if (total > availableQty) {
trNode.children().eq(remarksIndex).children().val("Qty not enough");
}
else {
trNode.children().eq(remarksIndex).children().val("");
} //table表头遍历 完毕
}