input输入框输入金额,限制只能输入正数且保留两位小数

 
<input type="text" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.').replace(/\.{2,}/g,'.').replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"  maxlength='20'  />

猜你喜欢

转载自blog.csdn.net/Dilemma_me/article/details/112602344