禁用写入输入类型编号HTML5 [英] Disable writing in input type number HTML5
本文介绍了禁用写入输入类型编号HTML5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想禁止写入类型编号的字段,以避免字符串数据,只写数字,那么如何只启用滚动条?
I want to disable writing into a field of type number, for avoiding strings data, and write just numbers, so how to enable scroll bars only ?
<form>
<input type="number" path="note" min="1" max="20"/>
</form>
推荐答案
如果你能够/允许使用jQuery,你可以在 type ='number'
上禁用 keypress
。
If you are able/allowed to use jQuery, you can disable keypress
on the type='number'
.
$("[type='number']").keypress(function (evt) {
evt.preventDefault();
});
这允许您在输入上使用向上和向下箭头,但不允许键盘输入。
This allows you to use up and down arrows on the input, but doesn't allow keyboard input.
这篇关于禁用写入输入类型编号HTML5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文