zoukankan      html  css  js  c++  java
  • input只允许输入数字和小数点,

    <html>

    <head>
    <meta http-equiv="content-Type" content="text/html;charset=gb2312">
    <title>js 只能输入数字和小数点</title>
    <script language="JavaScript" type="text/javascript">
    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("$#$",".");
    }
    </script>
    </head>
    <body>
    <!--把下面代码加到<body>与</body>之间-->
    只能输入数字和小数点的文本框:<input id="input1" onkeyup="clearNoNum(this)">
    </body>
    </html>

  • 相关阅读:
    模块 hashlib模块
    设计模式
    类中双下方法
    工作小结 常见定制类
    python collections模块
    启动脚本
    anaconda镜像
    理解python的可变参数
    使用spark
    python 异常处理
  • 原文地址:https://www.cnblogs.com/g-yang/p/6741951.html
Copyright © 2011-2022 走看看