html代码

<input type="text" style="width:50px" name="width[]" oninput = "clearNoNum(this)"/>米

Js代码

function clearNoNum(obj){
        obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是.
        obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
 
    }

robin_sky_html限制input框只能输入数字或小数及限制范围

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2021-10-19
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
猜你喜欢
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案