当前位置: 编程技术>jquery
Jquery遍历Table表头(示例)
来源: 互联网 发布时间:2014-09-03
本文导语: 本节内容: Jquery遍历Table表头。 例子: 代码示例: /** * 遍历table的表头 * 编辑:www. */ function CheckTotal(textBoxObj) { var trNode = textBoxObj.parent().parent(); //获取input的“爷爷”--tr var totalIdex = 0; var st...
本节内容:
Jquery遍历Table表头。
例子:
代码示例:
/**
* 遍历table的表头
* 编辑:www.
*/
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表头遍历 完毕
}
* 遍历table的表头
* 编辑:www.
*/
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表头遍历 完毕
}