<input type="text" id="currency" />
onChange and onblur Not works as typing
所以我想要当我(一旦)我输入它的格式时,就像
1000/000 或 100,000
最佳答案
function setFormat(id) {
if (document.getElementById(id).value != "") {
document.getElementById(id).value = parseFloat(document.getElementById(id).value.replace(/\//g, ""))
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, "/");
}
}
#currency {
text-align: left;
direction: ltr;
}
<input type="text" id="currency" oninput="setFormat('currency')" />
关于javascript - 如何在 JavaScript 中输入时向输入元素添加货币模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38672316/