zoukankan      html  css  js  c++  java
  • jquery控制输入框只输入数字,可以粘贴,判断粘贴内容是否全是数字

    <html>

    <script src="jquery-1.7.min.js"></script>
    <script>
    $(function(){
                    $("#text").keydown(function(event){   
            // 注意此处不要用keypress方法,否则不能禁用 Ctrl+V 与 Ctrl+V,具体原因请自行查找keyPress与keyDown区分,十分重要,请细查
                if ($.browser.msie) {  // 判断浏览器
                   if ( ((event.keyCode > 47) && (event.keyCode < 58)) || (event.keyCode == 8) || (event.keyCode == 86)) {  // 判断键值
                       return true;
                   } else {
                       return false;
                   }
               } else {
                   if ( ((event.which > 47) && (event.which < 58)) || (event.which == 8) || (event.which == 86) ) {
                       return true;
                   } else {
                       return false;
                   }
              }                         }).focus(function() {
                                     this.style.imeMode='disabled';   // 禁用输入法,禁止输入中文字符

                        }).bind("paste",function(){
         //alert($("#text").val());
         //return false;
         }).keyup(function(e){
         _v= $("#text").val();
         for(_i=0;_i<_v.length;_i++){
         _c=_v.charAt(_i);
         if(isNaN(_c)){
          $("#text").val("");
          return;
         }
         }
         });
    });

    </script>
    <body>
    <input id="text" name="text" type="text" >
    </body>
    </html>

  • 相关阅读:
    [LeetCode] Best Time to Buy and Sell Stock III
    [LeetCode] Implement strStr()
    [LeetCode] Wildcard Matching
    [LeetCode] Gray Code
    [LeetCode] Divide Two Integers
    [LeetCode] Flatten Binary Tree to Linked List
    [LeetCode] Binary Tree Maximum Path Sum
    [TopCoder][SRM] SRM 562 DIV 2
    推荐博客文章
    检测两点所确定直线上的像素坐标
  • 原文地址:https://www.cnblogs.com/webu/p/2794007.html
Copyright © 2011-2022 走看看