开发者

Restrict Keyboard Input jQuery

开发者 https://www.devze.com 2022-12-24 21:04 出处:网络
How would you go about Restricting Keyboard Input on a textbox using Jquery?开发者_如何学GoIf you don\'t want the user to be able to type anything in the text-box, then consider the readonly and disab

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

精彩评论

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

关注公众号