jquery - 使用jquery在文本框中动态添加值

标签 jquery asp.net-mvc-4 razorengine

我有 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/

相关文章:

javascript - 具有相同类的 anchor 标记在 jquery 中单击按钮时不返回值

javascript - Chartist动态输入

jquery - 从函数内部的函数返回值

jquery - 创建自定义推文按钮的最简单方法?

c# - 通过 cookie 控制对页面的访问

asp.net-mvc-4 - Windows Azure blob zip 并发送到客户端 (ASP.NET MVC)

c# - 在 MVC 4 应用程序中使用 Unity 和 Entity Framework 的最佳实践是什么

c# - 在 ASP.NET Core 中解析 Razor 字符串

.net - 尝试使用 Razor 引擎解析模板时,程序集 'mscorlib' 中的“System.Security.Principal.WindowsImpersonationContext”错误

c# - .NET Core <select> 有默认值吗?