zoukankan      html  css  js  c++  java
  • 数字输入框只能输入数字,禁止复制

    在项目中,有时候要只能输入数字的输入框,今日整理一下

    禁止右键和粘贴

    <body oncontextmenu="event.returnValue=false" onselectstart="event.returnValue=false"  onpaste="return false" >

    只能输入数字

     onKeypress="return /[d]/.test(String.fromCharCode(event.keyCode)))"

    input框的设置

    <input name="number" autocomplete="off" class="layui-input" placeholder="购买时长"
    style="ime-mode:disabled" onfocus=" this.style.imeMode='disabled' "
    onkeypress = 'return /^d$/.test(String.fromCharCode(event.keyCode||event.keycode||event.which))'
    oninput= 'this.value = this.value.replace(/D+/g, "")'
    onpropertychange='if(!/D+/.test(this.value)){return;};this.value=this.value.replace(/D+/g, "")'
    onblur = 'this.value = this.value.replace(/D+/g, "")'/>

    这样就完美的解决了

    注意不要用 type=number,  在h5中新加入的这个属性有一个bug,就是如果输入框中有非数字,无论是用js原生的还是jquery都获取不到输入框中的值

  • 相关阅读:
    Unity内生成深度贴图
    曲线细分
    Hermite插值
    查看静态库支持的CPU架构
    NLua引擎
    ImWindow
    Xenko Engine
    Fast Shadow Receiver
    2D色彩变换
    RVO
  • 原文地址:https://www.cnblogs.com/myzy/p/7093494.html
Copyright © 2011-2022 走看看