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、使用正则表达式

……

posted on 2013-07-25 20:18  办幼儿园+国家电网1亿  阅读(1213)  评论(0编辑  收藏  举报

返回顶部