Don#39;t allow typing alphabetic characters in a lt;input type=number /gt;(不允许在 lt;input type=number/gt; 中输入字母字符.)
问题描述
我需要有一个文本框,无论何时在其中输入,都应该只允许数字 [0-9].我使用了 type="number" ,它肯定拥有客户端验证,但也允许输入其他字母.我可以通过跟踪每个 keydown 并与正则表达式匹配来做到这一点,但我想知道是否有任何方法可以限制只使用 html 标签而不是在 JavaScript 中定义任何函数以在每个 keydown 中进行比较?
I need to have a textbox, where, whenever typed inside should ONLY allow numbers [0-9]. I've used type="number" which definitely holds the client side validation but also allows to type other alphabets. I can do it by tracking each keydown and matching with regex but I was wondering if there is any way I can restrict to type using only html tags and NOT defining any functions in JavaScript to compare in each keydown?
不足够的代码是:
<input type="number" id="txt_number" maxlength="70" name="txt_name" placeholder="Number">
感谢任何帮助.
推荐答案
你可以使用 jquery.numeric 插件.
看这里 类似的问题.
$(document).ready(function(){
$(".numeric").numeric();
});
这篇关于不允许在 <input type=number/> 中输入字母字符.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不允许在 <input type=number/> 中输入字母字符.
基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
