如何在输入 javascript 时将货币模式添加到输入元素?
how to add currency pattern to input element while typing in javascript?
<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')" />
<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')" />