jquery - 无法在表单提交之前禁用遮罩功能
问题描述
jQuery 插件可以完美地屏蔽文本框输入。但是,每次我提交表单时,输入值都不会保留,而是为零。该插件提供了我尝试过的销毁功能,但没有奏效。我不确定我做错了什么。我需要将输入屏蔽为货币,但是当我提交表单时,应提交实际值。提交我的 ActionResult 后返回相同的视图,因此我需要在文本框中以货币格式显示这些值。
jQuery插件以货币(货币)的形式屏蔽输入文本中的数据输入。
$(function() {
$('#currency').maskMoney({
prefix: '$ ',
allowNegative: true,
thousands: ',',
decimal: '.',
affixesStay: true,
removeMaskOnSubmit: true
});
});
//$(function () {
// $('#myBtn').click(function () {
// $('#currency').maskMoney('destroy');
// });
//});
//$("#submitBtn").click(function () {
// $("#currency").maskMoney('destroy');
//});
<div id="displayResultDiv">
<div class="row">
<div class="col">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col">
@using (Ajax.BeginForm("CREDebtServiceCoverageRatioCalc", "Calculators", new { Area = "Toolbox" }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "displayResultDiv", InsertionMode = InsertionMode.Replace }, new { id = "myform" })) {
<div class="row">
<div class="col">
<table class="table table-sm">
<thead>
<tr>
<th scope="col">@ViewBag.pageHeading</th>
<th scope="col"><input type="button" value="Perform Analysis" class="btn btn-outline-success btn-sm" id="myBtn" /></th>
<th scope="col"><input type="submit" value="Perform Analysis" class="btn btn-outline-success btn-sm" id="submitBtn" /></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="col">Income</th>
<th scope="col">@ViewBag.FirstFYE</th>
<th scope="col">@ViewBag.SecondFYE</th>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearRents, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearRents, htmlAttributes: new { @class = "form-control form-control-sm", id = "currency" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearRents, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearReimbursement, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearReimbursement, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearReimbursement, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearOtherIncome, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearOtherIncome, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearOtherIncome, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="col">Expenses</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearAdvertising, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearAdvertising, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearAdvertising, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearRepairsAndMaintenance, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearRepairsAndMaintenance, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearRepairsAndMaintenance, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearCommission, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearCommission, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearCommission, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearInsurance, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearInsurance, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearInsurance, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearLegalAndProfessionalFees, new { @class = "font-weight-bold" })</th>
<td class="boder-right">@Html.TextBoxFor(x => x.FirstYearLegalAndProfessionalFees, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearLegalAndProfessionalFees, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearManagementFee, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearManagementFee, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearManagementFee, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearTaxes, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearTaxes, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearTaxes, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearUtilities, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearUtilities, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearUtilities, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearSalariesAndWages, new { @class = "font-weight-bold" })</th>
<td class="boder-right">@Html.TextBoxFor(x => x.FirstYearSalariesAndWages, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearSalariesAndWages, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearReplacementReserves, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearReplacementReserves, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearReplacementReserves, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row" style="padding-left:30px;">@Html.LabelFor(x => x.FirstYearOtherOperatingExpenses, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.TextBoxFor(x => x.FirstYearOtherOperatingExpenses, new { @class = "form-control form-control-sm" })</td>
<td>@Html.TextBoxFor(y => y.SecondYearOtherOperatingExpenses, new { @class = "form-control form-control-sm" })</td>
</tr>
<tr>
<th scope="row">@Html.LabelFor(x => x.FirstYearNetOperatingIncome, new { @class = "font-weight-bold" })</th>
<td class="border-right">@Html.DisplayTextFor(x => x.FirstYearNetOperatingIncome)</td>
<td>@Html.DisplayTextFor(x => x.SecondYearNetOperatingIncome)</td>
</tr>
</tbody>
</table>
</div>
</div>
}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
public PartialViewResult CREDebtServiceCoverageRatioCalc()
{
ViewBag.pageHeading = "Real Estate Ability To Pay";
ViewBag.FirstFYE = String.Format("{0:MM/dd/yyyy}", FiscalYearEnds.FirstFiscalYearEndDate());
ViewBag.SecondFYE = String.Format("{0:MM/dd/yyyy}", FiscalYearEnds.SecondFiscalYearEndDate());
CREAbilityToPayInputs input = (CREAbilityToPayInputs)TempData.Peek("CREAbilityToPayInputValues");
CREIncome cREIncome = new CREIncome(input.FirstYearRents, input.FirstYearReimbursement, input.FirstYearOtherIncome);
double firstYETotalRevenues = cREIncome.TotalRevenues();
CREIncome cREIncomeSecondYE = new CREIncome(input.SecondYearRents, input.SecondYearReimbursement, input.SecondYearOtherIncome);
double secondYETotalRevenues = cREIncomeSecondYE.TotalRevenues();
CREExpenses cREExpenses = new CREExpenses(input.FirstYearAdvertising, input.FirstYearRepairsAndMaintenance, input.FirstYearCommission, input.FirstYearInsurance, input.FirstYearLegalAndProfessionalFees, input.FirstYearManagementFee, input.FirstYearTaxes, input.FirstYearUtilities, input.FirstYearSalariesAndWages, input.FirstYearReplacementReserves, input.FirstYearOtherOperatingExpenses);
double totalOperatingExpenses = cREExpenses.TotalOperatingExpenses();
CREExpenses cREExpensesSecondYE = new CREExpenses(input.SecondYearAdvertising, input.SecondYearRepairsAndMaintenance, input.SecondYearCommission, input.FirstYearInsurance, input.SecondYearLegalAndProfessionalFees, input.SecondYearManagementFee, input.SecondYearTaxes, input.SecondYearUtilities, input.SecondYearSalariesAndWages, input.SecondYearReplacementReserves, input.SecondYearOtherOperatingExpenses);
double secondYETotalOperatingExpenses = cREExpensesSecondYE.TotalOperatingExpenses();
CREAbilityToPay cREAbilityToPayFirstYE = new CREAbilityToPay(firstYETotalRevenues, totalOperatingExpenses, 1,1,1);
CREAbilityToPay cREAbilityToPaySecondYE = new CREAbilityToPay(secondYETotalRevenues, secondYETotalOperatingExpenses, 1, 1, 1);
CREAbilityToPayInputs results = new CREAbilityToPayInputs
{
FirstYearNetOperatingIncome = String.Format("{0:C}", cREAbilityToPayFirstYE.NetOperatingIncome()),
SecondYearNetOperatingIncome = String.Format("{0:C}", cREAbilityToPaySecondYE.NetOperatingIncome()),
FirstYearRents = input.FirstYearRents,
SecondYearRents = input.SecondYearRents,
FirstYearReimbursement = input.FirstYearReimbursement,
SecondYearReimbursement = input.SecondYearReimbursement,
FirstYearOtherIncome = input.FirstYearOtherIncome,
SecondYearOtherIncome = input.SecondYearOtherIncome,
FirstYearAdvertising = input.FirstYearAdvertising,
SecondYearAdvertising = input.SecondYearAdvertising,
FirstYearRepairsAndMaintenance = input.FirstYearRepairsAndMaintenance,
SecondYearRepairsAndMaintenance = input.SecondYearRepairsAndMaintenance,
FirstYearCommission = input.SecondYearCommission,
SecondYearCommission = input.SecondYearCommission,
FirstYearInsurance = input.FirstYearInsurance,
SecondYearInsurance = input.SecondYearInsurance,
FirstYearLegalAndProfessionalFees = input.FirstYearLegalAndProfessionalFees,
SecondYearLegalAndProfessionalFees = input.SecondYearLegalAndProfessionalFees,
FirstYearManagementFee = input.FirstYearManagementFee,
SecondYearManagementFee = input.SecondYearManagementFee,
FirstYearTaxes = input.FirstYearTaxes,
SecondYearTaxes = input.SecondYearTaxes,
FirstYearUtilities = input.FirstYearUtilities,
SecondYearUtilities = input.SecondYearUtilities,
FirstYearSalariesAndWages = input.FirstYearSalariesAndWages,
SecondYearSalariesAndWages = input.SecondYearSalariesAndWages,
FirstYearReplacementReserves = input.FirstYearReplacementReserves,
SecondYearReplacementReserves = input.SecondYearReplacementReserves,
FirstYearOtherOperatingExpenses = input.FirstYearOtherOperatingExpenses,
SecondYearOtherOperatingExpenses = input.SecondYearOtherOperatingExpenses
};
return PartialView("_CREAbilityToPayInputForm", results);
}
解决方案
推荐阅读
- svg - Html中的 SVG 问题
- javascript - 如何使 Filepond 图像可拖动?
- mysql - 连接到数据库时出错。用户“root”@“localhost”的访问被拒绝(使用密码:YES)
- react-native - useState() 具有初始值但未反映在状态变量中的钩子
- hdfs - Hue / Filebrowser 文件上传/下载 API?
- javascript - 我可以在没有数据库的情况下在客户端的静态网站上轻松实现全文搜索吗?
- javascript - d3中带有文本的矩形周围的网络
- flutter - 颤振2.2。桌面测试版支持 Firestore?
- javascript - 如何从 JS 向 Flask 发送确认“ok”/“”cancel”
- android - Appium + Selenium - microsoft azure 登录页面上的应用程序活动和应用程序包更改