zoukankan      html  css  js  c++  java
  • 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;
      }
    };
  • 相关阅读:
    HashMap源码解析
    深入理解Java字符串
    Netty粘包、半包
    Netty源码分析-Future和Promise
    Lock简介
    一、Netty中的EventLoop
    对象实例化内存布局与访问定位
    运行时数据区概述及线程
    TCP三次握手和四次挥手
    Redis线程IO模型-Redis 单线程为什么还能这么快?
  • 原文地址:https://www.cnblogs.com/lvyueyang/p/6812246.html
Copyright © 2011-2022 走看看