开发者

How do I make a textbox take only numeric characters using jQuery? [closed]

开发者 https://www.devze.com 2022-12-25 21:31 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago. 开发者_运维知识库

I need to make a textbox that only allows numeric characters. I've looked through several numeric plugins and can't find one that I like. I'm looking for either a plugin recommendation with the associated URL or syntax showing how to get started on making my own plugin.


$("#testinput").keypress(function(e){
  if (isNaN(String.fromCharCode(e.which))){
    return false;
  }
});


You can start by implementing the function with JQuery and then integrate it into a (configurable) plugin.

To handle textbox input you should intercept keydown event on textbox and then prevent the input if it's not allowed.

To write a plugin you can start from here: http://www.learningjquery.com/2007/10/a-plugin-development-pattern http://www.learningjquery.com/2009/03/making-a-jquery-plugin-truly-customizable

0

精彩评论

暂无评论...
验证码 换一张
取 消