2

我有一张表,其中有一个带有一些值的跨度标签和 6 个输入,其 ID 自动生成,其中值从数据库更新,可以更改。

<td><span id="Day${c.id}">/*generated automatically*/</span></td>
<td><input class="inp${c.id}" name="b1-${c.id}" id="b1${c.id}" value="${c.exp?.b1}" type="text"/></td>
<td><input class="inp${c.id}" name="b2-${c.id}" id="b2-${c.id}" value="${c.exp?.b2}" type="text"/></td>
<td><input class="inp${c.id}" name="b3-${c.id}" id="b3-${c.id}" value="${c.exp?.b3}" type="text"/></td>
<td><input class="inp${c.id}" name="b4-${c.id}" id="b4-${c.id}" value="${c.exp?.b4}" type="text"/></td>
<td><input class="inp${c.id}" name="b5-${c.id}" id="b5-${c.id}" value="${c.exp?.b5}" type="text"/></td>
<td><input class="inp${c.id}" name="b6-${c.id}" id="b6-${c.id}" value="${c.exp?.b6}" type="text"/></td>
<td><span id="Total${c.id}">0</span></td>

我需要像这样实时计算 onKeyUp 表达式:

total = span*(input1*(input2+input3)+input4+input5+input6)

4

2 回答 2

0

try following,

$('table').find('input').each(function()
{
    //  this.do_your_own_thing here....
    // read jquery doc to see all options
})
于 2012-05-26T08:47:30.983 回答
0

[Edited for the very specific requirement of OP]

$(document).ready(function(){
    $('input[id^="inp"]').keyup(function(){
        var total = 0;
        var temp = 0;
        $('input[id^="inp"]').each(function(i){
            if(i==0)
                total = $(this).val();
            else if(i==1)
                temp = $(this).val();
            else if(i==2)
                total = total*(temp+$(this).val());
            else
                total += $(this).val();
        });

        total *= $('span[id^="Day"]').val();
        $('span[id^="Total"]').val(total);
    });
});
于 2012-05-26T08:49:32.310 回答