$('#当前input').on('input propertychange', function () {
var thisValue = $(this).val();
//输入值了
if(thisValue){
//如果输入的不是.或者不是数字,替换 g:全局替换
thisValue = thisValue.replace(/[^(\d|.)]/g,"");
//不能有两个点
if(thisValue.indexOf(".")>-1 && (thisValue.substring(thisValue.indexOf(".")+1,thisValue.length)).indexOf(".")>-1){
//保留第一个点和之前的数据
thisValue = thisValue.substring(0,thisValue.indexOf(".",thisValue.indexOf(".")+1));
}
//点出现在第一位就变成零点
if(thisValue.indexOf(".") == "0"){
thisValue = thisValue.replace(".","0.")
}
//00,01 等变成 0 ,1 ...
if(thisValue=="00" || thisValue=="01" || thisValue=="02" || thisValue=="03" || thisValue=="04" || thisValue=="05" || thisValue=="06" || thisValue=="07" || thisValue=="08" || thisValue=="09"){
thisValue = thisValue.replace("0","");
}
$(this).val(thisValue);
}
})
限制input 只能输入正数和零
于 2022-07-12 09:19:33 首次发布