<input type="number" name="ram" onkeyup="numberWithCommas(this.value)" id="num"/>
此代码显示了在文本框中添加逗号的方式以及如何添加逗号:
<input type="number" name="ram" onkeyup="c(this.value)" id="**num**"/>
<p id="show"></p>
<script>
function addcomm(x) {
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
document.getElementById('show').innerHTML= parts.join(".");
//document.getElementById('num').value=parts.join(".");
return parts.join(".");
}
</script>