Jquery一个遍历Table表头的例子

        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("");
            }
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值