我有 Razor UI,其中有 3 列,如下所示:
DEnom amt totalamt
$1 0 0
$5 4 20
$10 1 10
$50 0 0
$100 2 200
Total 7 230
这里的面额可能会不时变化。
因此使用 for 循环填充 UI,如下所示:
@for (int count = 0; count < Model.Bill.Count(); count++)
{
<tr>
<td>
@Html.LabelFor(m => m.Bill[count].BillDenom)
</td>
<td>
@Html.TextBoxFor(m => m.Bill[count].Count)
</td>
<td>
@Html.TextBoxFor(m => m.Amount)
</td>
</tr>
}
现在,如果我输入每个面额的金额,则应动态计算相应的总金额和总金额。如何使用 jQuery 实现这一点。
最佳答案
在生成 Denom_+count、amt_count 和totalamt_+count 等控件时动态为所有控件生成 ID。
为 Denom 文本框提供一个类,并在 jquery on event 中编写 keyup 功能
$(document).on('keyup','.SpecifiedClass',function(){
var id=$(this).attr('id');
var pointer=id.split('_')[1];
//Now you have the pointer to that row so you can calculate the other
//controls value and use the logic for summation
})
关于jquery - 使用jquery在文本框中动态添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21300145/