• input输入限制(持续更新)


    1.只读文本框内容

    <!--  在input里添加属性值 readonly  -->
    <input type="text" value="" readonly>

    2.只能输入数字(有闪动)

    <input type="text" onkeyup="value=value.replace(/[^d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))">

    3.只能输入英文和数字

    <input onkeyup="value=value.replace(/[W]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))">

    4.只能输入数字和小数点后两位

    <input type="text" onkeyup="clearNoNum(this)">
    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("$#$",".");
      obj.value = obj.value.replace(/^(-)*(d+).(dd).*$/,'$1$2.$3'); //只能输入两个小数
    };

    5.只能输入整数

    function zhengShu(obj){
      obj.value = obj.value.replace(/[^d]/g,""); //清除"数字"和"."以外的字符
      obj.value = obj.value.replace(/^./g,""); //验证第一个字符是数字而不是
    }

    6.限制文本框输入字数

    <form name="form" action="" method="post">
      <textarea class="editbox2" onkeydown="numPic(this.form.memo,this.form.remLen,10)" onkeyup="numPic(this.form.memo,this.form.remLen,10)" name="memo" cols="45" rows="8" wrap="on"></textarea>
      <br>共可输入10字,还剩
      <input class="editbox1" readOnly maxLength="3" size="3" value="10" name="remLen">字。
      <br>
      <input class="bottom" type="submit" value=" 提交 " name="submit">
      <input class="bottom" type="reset" value=" 重置 " name="reset">
    </form>
    function numPic(field, countfield, maxlimit) {
      if (field.value.length > maxlimit){
        field.value = field.value.substring(0, maxlimit);
      }else{
        countfield.value = maxlimit - field.value.length;
      }
    };
  • 相关阅读:
    Maven部署构件至远程仓库
    Maven远程仓库的认证
    Maven远程仓库的配置
    Maven实战系列文章
    使用Maven私服的好处
    使用Mavne生成可以执行的jar文件
    Visual Studio for Mac 简介
    HTTP 2.0与HTTP 1.1区别
    使用Microsoft的IoC框架:Unity来对.NET应用进行解耦
    围绕央行系统升级所产生的常见问题
  • 原文地址:https://www.cnblogs.com/lvyueyang/p/6812246.html
Copyright © 2020-2023  润新知