如何在“总值”中添加千位分隔符?这样看起来就好像1 000或23000->之间有成千上万的空白,不是昏迷而是空白... 同样,当我输入INPUT 5位数字时,总值消失了...
这里是Fiddle
HTML:
<input type="text" id="nazwa" min="0" max="500000" >
<br><br>
Total value: <span id="total_expenses1"></span>
JavaScript / jQuery:
$('#nazwa').keyup(function(){ // run anytime the value changes
var raz = document.getElementById('nazwa');
var dwa = document.getElementById('total_expenses1');
var firstValue = Number($('#nazwa').val()); // get value of field
var secondValue = 1.15; // convert it to a float
raz.value = THOUSAND_SEPARATOR(this.value);
var mega = $('#total_expenses1').html(Math.ceil(firstValue * secondValue));
THOUSAND_SEPARATOR(mega.value);
// add them and output it
});
目前,千位分隔符功能仅适用于输入值
答案 0 :(得分:0)
document.getElementById('total_expenses1').innerHTML = THOUSAND_SEPARATOR(String(Math.ceil(Number((this.value || '').replace(/\s/g, '')) * secondValue)));