限制只能输入小数点后两位

<script type="text/javascript">
function strNumber(elm){
elm.value = elm.value.replace(/^[^0-9.]*(\d*[\.]?\d{0,2})\w*$/,'$1');
}
</script>

<input type="text"  onkeyup="strNumber(this)"/>

posted @ 2015-10-22 16:12  浅夏、  阅读(276)  评论(0编辑  收藏  举报