开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜