jquery文本框只输入数字插件

  //use: $("selector").inputOnlyNum();只输入数字
  (function($) {
      $.fn.inputOnlyNum = function() {
          this.keypress(function(e) {
              if (e.which == 8 || e.keyCode == 9) return true; //Backspace & Tab in ff
              var b = /^[\d\.-]$/.test(String.fromCharCode(e.which));
              if (b) {
                  window.setTimeout(function() {
                      if (isNaN($(e.target).val()) && $(e.target).val() != '-') { $(e.target).val(''); }
                  }, 10);
              }
              return b;
          }).bind("paste", function() { return !isNaN(clipboardData.getData('text')); })
                 .bind("dragenter", function() { return false; }).css("ime-mode", "disabled");
      };
  })(jQuery);
posted @ 2010-11-01 13:26  庚武  Views(933)  Comments(0Edit  收藏  举报