【发布时间】:2020-12-29 22:37:21
【问题描述】:
当我只使用计算功能时,它工作正常。但是当我添加输入数字逗号函数时,它会将结果编号设为 NaN。我该如何解决这个问题?
这是我的 HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="form">
<div class="container forms">
<h3 class="first">chicken</h3>
<input type="text" id="value1"/> times
<h4 class="second">pizza</h4>
<input type="text" id="value2"/> pieces
</div>
<button class="calculate" type="button" onclick="cal()">sum</button>
<h5 id="result"></h5>
</section>
她是我的JS
const cal = () => {
const A = value1.value,
B = value2.value;
const res = A * (9 / 100) * (100 / B).toLocaleString();
result.innerText = `you have ${new Intl.NumberFormat('ja-JP', {
style: 'currency',
currency: 'JPY',
}).format(res)} Yen, sir.`;
};
$('input').keyup(function (event) {
// skip for arrow keys
if (event.which >= 37 && event.which <= 40) return;
// format number
$(this).val(function (index, value) {
return value.replace(/\D/g, '').replace(/\B(?=(\d{3})+(?!\d))/g, ',');
});
});
感谢您的帮助。
【问题讨论】:
标签: javascript nan