![](/img/trans.png)
[英]How to add thousand separator to a String with JS or JQuery in this particular function?
[英]JavaScript/jQuery --> How to add thousand separator to 'Total value?'
如何在“总值”中添加千位分隔符? 这样看起来就好像1 000或23000->之间有成千上万的空格,不是昏迷而是空格...同样,当我写入INPUT 5位数字时,总值消失了...
这是小提琴
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
});
至于现在千分隔符功能仅适用于输入值
document.getElementById('total_expenses1').innerHTML = THOUSAND_SEPARATOR(String(Math.ceil(Number((this.value || '').replace(/\s/g, '')) * secondValue)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.