【发布时间】:2021-09-18 14:35:32
【问题描述】:
我想通过将 UnitAmount 和用户输入的数量相乘来计算总金额。 然后我需要将该总金额传递给总金额标签字段。到目前为止,这是我的代码,
<div class="col-md-3 col-sm-6">
<div class="form-group">
Unit Amount
<div class="col-md-10">
@Html.EditorFor(model => model.Unit_Amount, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Unit_Amount, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="form-group">
Requesting Qty
<div class="col-md-10">
@Html.EditorFor(model => model.Qty, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Qty, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="form-group">
Total Amount
<div class="col-md-10">
@Html.LabelFor(model => model, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Qty, "", new { @class = "text-danger" })
</div>
</div>
</div>
我也得到了 jquery,但我认为我做错了。
<script>
$(document).ready(function () {
$('.Qty').on('change', function (evt) {
var $row = $(this).parents('tr');
var rate = Number($row.find('.Unit_Amount').text());
var qty = Number($(this).val());
var total = rate * qty;
$row.find('.Total').text(total);
});
});
</script>
你能帮我解决这个问题吗?谢谢。
【问题讨论】:
标签: jquery asp.net asp.net-mvc asp.net-mvc-4