开发者

Restrict Keyboard Input jQuery

How would you go about Restricting Keyboard Input on a textbox using Jquery?开发者_如何学Go


If you don't want the user to be able to type anything in the text-box, then consider the readonly and disabled attributes. If the data in the textbox is needed at the server side, make it readonly. If not, make it disabled.

<input type="text" readonly="readonly" />

<input type="text" disabled="disabled" />

If you want the user to be able to type in something, but only restrict certain types of characters such as numbers only, then listen to the keyup event on the textbox. It is fired whenever a key is released inside the text box. On this events callback, check the value of the textbox, and make changes to the value as necessary.


for <input type="text"> use attribute maxlength

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜