视图中的数据表:
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 form-group">
<table id="mainDivInvoiceItemTable" class="table table-hover" style="width: 100%">
<thead>
<tr>
<th style="text-align: center"><strong><u>I</u></strong>tem Name</th>
<th style="text-align: center">Discription</th>
<th style="text-align: center"><strong><u>Q</u></strong>uantity</th>
<th style="text-align: center"><strong><u>U</u></strong>nit Price</th>
<th style="text-align: center"><strong><u>T</u></strong>ax 1</th>
<th style="text-align: center"><strong><u>T</u></strong>ax 2</th>
<th style="text-align: center">Total Before Tax</th>
<th style="text-align: center"> </th>
</tr>
</thead>
<tbody>
<tr class="hidden">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<%
if (Model.NewInvoiceItemList != null)
{
for (int i = 0; i < Model.NewInvoiceItemList.Count; i++)
{
string cls = string.Empty;
if (string.Compare(Model.NewInvoiceItemList[i].ItemDescription, "13335588990101") == 0)
{
cls = "hide";
}
%>
<tr class="InvoiceItemTableRow <%: cls %>"", id="<%:"NewItemRow"+i%>">
<td style="text-align:center">
<%: Html.DropDownList(string.Format("NewInvoiceItemList[{0}].ItemList", i), Model.GetSelectedItemList(Model.NewInvoiceItemList[i].InvoiceItemId, Model.NewInvoiceItemList[i].ItemName), new { @class = "InvoiceItemRow DDList1", @id = string.Format("NewInvoiceItemList_{0}__ItemList", i), @style="width: 125px; text-align:center" })%>
<input id="<%: string.Format("NewInvoiceItemList_{0}__ItemName", i) %>" name="<%: string.Format("NewInvoiceItemList[{0}].ItemName", i) %>" type="hidden" value="<%: Model.NewInvoiceItemList[i].ItemName %>" data-tag="12345" />
</td>
<td style="text-align:center">
<%: Html.TextBoxFor(model => model.NewInvoiceItemList[i].ItemDescription, new { @class = "InvoiceItemRow1", @style="width: 150px; text-align:center" })%>
<div class="note"><%: Html.ValidationMessageFor(model => model.NewInvoiceItemList[i].ItemDescription, "", new { @style="color:red;"}) %></div>
</td>
<td style="text-align:center">
<%: Html.TextBoxFor(model => model.NewInvoiceItemList[i].Quantity, new { @class = "InvoiceItemRow Qty AmountTextBox", @style="width: 125px; text-align:center" })%>
<div class="note"><%: Html.ValidationMessageFor(model => model.NewInvoiceItemList[i].Quantity, "", new { @style="color:red;"}) %></div>
</td>
<td style="text-align:center">
<%: Html.TextBoxFor(model => model.NewInvoiceItemList[i].UnitPrice, new { @class = "InvoiceItemRow Price AmountTextBox", @style="width: 125px; text-align:center" })%>
<div class="note"><%: Html.ValidationMessageFor(model => model.NewInvoiceItemList[i].UnitPrice, "", new { @style="color:red;"}) %></div>
</td>
<td style="text-align:center">
<%:Html.CustomDropdown(model => model.NewInvoiceItemList[i].Tax1Id, string.Format("NewInvoiceItemList_{0}__Tax1Id", i), string.Format("NewInvoiceItemList[{0}].Tax1Id", i), Model.GetSelectedTaxList(Model.NewInvoiceItemList[i].Tax1Id, Model.NewInvoiceItemList[i].Tax1Name, Model.NewInvoiceItemList[i].Tax1Val.ToString()), "Text", new Dictionary<string, object> { { "class", "InvoiceItemRow DDList2 invoicetax" }, {"style", "width: 125px; text-align:center" } })%>
<input id="<%: string.Format("NewInvoiceItemList_{0}__Tax1Name", i) %>" name="<%: string.Format("NewInvoiceItemList[{0}].Tax1Name", i) %>" type="hidden" value="<%: Model.NewInvoiceItemList[i].Tax1Name %>" />
<input id="<%: string.Format("NewInvoiceItemList_{0}__Tax1Val", i) %>" name="<%: string.Format("NewInvoiceItemList[{0}].Tax1Val", i) %>" type="hidden" value="<%: Model.NewInvoiceItemList[i].Tax1Val %>" />
<div class="note"><%: Html.ValidationMessageFor(model => model.NewInvoiceItemList[i].Tax1Id, "", new { @style="color:red;"}) %></div>
</td>
<td style="text-align:center">
<%:Html.CustomDropdown(model => model.NewInvoiceItemList[i].Tax2Id, string.Format("NewInvoiceItemList_{0}__Tax2Id", i), string.Format("NewInvoiceItemList[{0}].Tax2Id", i), Model.GetSelectedTaxList(Model.NewInvoiceItemList[i].Tax2Id, Model.NewInvoiceItemList[i].Tax2Name, Model.NewInvoiceItemList[i].Tax2Val.ToString()), "Text", new Dictionary<string, object> { { "class", "InvoiceItemRow DDList2 invoicetax" }, {"style", "width: 125px; text-align:center" } })%>
<input id="<%: string.Format("NewInvoiceItemList_{0}__Tax2Name", i) %>" name="<%: string.Format("NewInvoiceItemList[{0}].Tax2Name", i) %>" type="hidden" value="<%: Model.NewInvoiceItemList[i].Tax2Name %>" />
<input id="<%: string.Format("NewInvoiceItemList_{0}__Tax2Val", i) %>" name="<%: string.Format("NewInvoiceItemList[{0}].Tax2Val", i) %>" type="hidden" value="<%: Model.NewInvoiceItemList[i].Tax2Val %>" />
<div class="note"><%: Html.ValidationMessageFor(model => model.NewInvoiceItemList[i].Tax2Id, "", new { @style="color:red;"}) %></div>
</td>
<td style="text-align:center">
<%: Html.TextBoxFor(model => model.NewInvoiceItemList[i].BeforeTaxAmount, new { @class = "InvoiceItemRow BeforeTaxAmount AmountTextBox", @readonly = "readonly", @style="width: 125px; text-align:center" })%>
</td>
<td style="text-align:center">
<a href="#" id="NewItemDelete<%:i %>" data-invitemid="0" class="DeleteItem" style="width: 10px; text-align:center" >
<img src="/Images/IconDelete2D.png" title="Delete" alt="Delete" style="height: 20px; width: 15px" />
</a>
<%: Html.HiddenFor(model => model.NewInvoiceItemList[i].InvoiceItemId)%>
<%: Html.HiddenFor(model => model.NewInvoiceItemList[i].ExpenseList)%>
<%: Html.HiddenFor(model => model.NewInvoiceItemList[i].ProjectId)%>
<%: Html.HiddenFor(model => model.NewInvoiceItemList[i].ProjectName)%>
<%: Html.HiddenFor(model => model.NewInvoiceItemList[i].ProjectStaffId)%>
<%: Html.HiddenFor(model => model.NewInvoiceItemList[i].StaffName)%>
<%: Html.HiddenFor(model => model.NewInvoiceItemList[i].ExpenseCategoryId)%>
<%: Html.HiddenFor(model => model.NewInvoiceItemList[i].CategoryName)%>
</td>
</tr>
<% }
}%>
</tbody>
</table>
</div>
</div>
在“数量”文本框中更改值时,重新计算并将值分配给BeforeTaxAmount文本框的JQuery代码。
$(“#mainDivInvoiceItemTable,#mainDivInvoiceServiceTable”)。on('blur','。Qty',function(){
var qtytextboxid = $(this).attr("id");
var qtytextboxvalue = $('#' + qtytextboxid).val();
var pricetextboxid = qtytextboxid.replace("Quantity", "UnitPrice");
var pricetextboxvalue = $('#' + pricetextboxid).val();
var amtbeforetaxtextboxid = qtytextboxid.replace("Quantity", "BeforeTaxAmount");
var BeforeTaxValue = qtytextboxvalue * pricetextboxvalue;
$('#' + amtbeforetaxtextboxid).val(BeforeTaxValue.toFixed(2));
subTotal();
});
当数据表未折叠时,一切正常。但是当它崩溃时,屏幕上不再显示BeforeTaxAmount文本框,并且不会将值分配给它。
如果在数据表崩溃时它不在屏幕上,我如何确保将值分配给BeforeTaxAmount?
非常感谢帮助。我看了一眼,然后看了一下,然后咕咕咕咕......
谢谢,
JRD
答案 0 :(得分:0)
$('text', editor.field( 'Quantity' ).node()).on( 'change', function () {
var c = editor.field( 'Cost' ).val();
var q = editor.field( 'Quantity' ).val();
var total = (c * q);
editor.val( 'Total', total );
} );
这是我使用的可能有用的东西。所以基本上在数量变化时,它会通过将成本和数量相乘来更新总字段。