【发布时间】:2020-06-07 15:15:37
【问题描述】:
我正在尝试将计算器从我的 Excel 电子表格复制到网页。 第一个字段是自然数的输入(不带逗号),第二个是一些货币值(带逗号、点等),第三个是总数,但它有一个定义的值(例如,0,38 美分)。两个字段必须相乘并在第三个字段中给出结果。
我尝试使用遮罩插件创建遮罩,但出现了几个错误。也尝试使用 toLocaleStrings。
HTML
<form>
<!-- simple number to start the calculation -->
<label>Natural Number</label>
<input type="text" id="base" />
<br>
<!-- currency including the cents -->
<label>Currency value</label>
<input type="text" id="ticket" />
<br>
<!-- If the first field is "1" and the second is "1,00", this field has a value of 0.38 cents. -->
<label>Currency total</label>
<input type="text" id="cost" readonly /></form>
JQUERY
$(document).ready(function(){
$('#cost').mask('000.000.000.000.000,00', {reverse: true});
$('#base').keyup(calculate);
$('#ticket').keyup(calculate)
function calculate(e) {
$('#cost').val($('#base').val() * $('#ticket').val() * 0.38).trigger('input')
}
});
【问题讨论】:
-
你能告诉我们预期的货币价值格式吗?您是否尝试过使用 Maskmoney github.com/plentz/jquery-maskmoney... 请在您的问题中添加预期的格式
-
我在帖子中添加了一个结果示例。我尝试了一个 maskMoney,实际上是一个更有效的面具。但有时总货币不显示小数。
标签: javascript jquery input field multiplication