js怎么判断字符串中只有数字和小数点-待补充

js怎么判断字符串中只有数字和小数点

1、keyCode的使用

<input type ='text' onkeypress = "return check()">

<script>
function check(){
  var _iKeyCode = window.event.keyCode;

    if ((_iKeyCode < 48  || _iKeyCode > 57) && _iKeyCode!=46)
      window.event.returnValue = false;
    return true;

}
</script>

2、使用正则表达式

……

原文地址:https://www.cnblogs.com/aiyouku/p/keyCode.html