zoukankan      html  css  js  c++  java
  • 关于js的keyCode

    原生js的event对象有三个键盘事件的值:
    1) charCode: 被点击键的Unicode值
    2) keyCode: 被点击键的ASCII十进制值
    3) which: 字母数字键的charCode或者keyCode,具体可以自己试试

    Mootools的event被封装后,统一成为code和key:

    event.code = event.which || event.keyCode;
    event.key = String.fromCharCode(code).toLowerCase();
    

    写了个方法,用于控制数字输入

    // 价格字符串格式(小数点后最多两位)
    $$('.jsForPrice').addEvents({
         'keypress': function(ev){
              var result;
              if(this.val().length === 0 || this.val().test('\.')){// 只能有1个点号
                   result = ev.code>=48&&ev.code<=57 || ev.code==8;
              }else{
                   result = ev.code>=48&&ev.code<=57||ev.code==8||ev.code==46;
              }
              return result;
         },
         'keyup': function(ev){
              if(this.val().test('\.')){
                   if(this.val().split('.')[1].length>2){
                        this.val(this.val().substring(0, this.val().length-1))
                   }
              }
              //console.log(this.val().test('^[0-9]+(\.[0-9]{1,2}){0,1}$'))
         }
    });
    

    参考:stackoverflow

  • 相关阅读:
    强连通 HDU 1827
    强联通 HDU 2767 3836
    强连通 HDU 1269
    网络流 poj 2135
    强联通 poj 2762
    android20-[【转】Android的EditText自动获取焦点并弹出输入法问题]
    windows开发中的一点总结
    android19
    android18
    android17
  • 原文地址:https://www.cnblogs.com/timelyxyz/p/3708116.html
Copyright © 2011-2022 走看看