基于js实现的限制文本框只可以输入数字
作者:劳卜 时间:2024-04-25 13:06:46
话不多说,直接附上源码,仅供参考
封装了一下,要用的话直接调用下面getEvent函数即可
function getEvent() {
if (document.all) {
return window.event; //for ie
}
func = getEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if (arg0) {
if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
return arg0;
}
}
func = func.caller;
}
return null;
};
function doit(){
var ev = getEvent();
if(ev.keyCode < 8) {return false;}
else if(ev.keyCode > 8 && ev.keyCode < 48) {return false;}
else if(ev.keyCode > 57 && ev.keyCode <96) {return false;}
else if(ev.keyCode > 105) {return false;}
else {return true;}
};
来源:http://www.cnblogs.com/luozhihao/p/4586140.html
标签:js,文本框,数字
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python进阶学习之特殊方法实例详析
2022-03-03 22:15:04
python实现用于测试网站访问速率的方法
2023-07-28 19:12:02
MySql循环插入数据
2010-10-14 13:50:00
Python实现基于POS算法的区块链
2023-10-30 01:47:19
![](https://img.aspxhome.com/file/2023/1/67291_0s.png)
在notepad++中实现直接运行python代码
2022-08-19 09:52:00
![](https://img.aspxhome.com/file/2023/6/72026_0s.png)
python性能测试工具locust的使用
2021-06-28 09:12:50
![](https://img.aspxhome.com/file/2023/5/89095_0s.png)
python通过ffmgep从视频中抽帧的方法
2023-10-02 12:35:39
Mongoose经常返回e11000 error的原因分析
2024-05-03 15:36:05
python实现计算器简易版
2021-01-25 22:43:15
![](https://img.aspxhome.com/file/2023/3/131353_0s.jpg)
Flask-WTF表单的使用方法
2022-03-07 07:34:59
golang 对私有函数进行单元测试的实例
2024-05-13 10:43:54
浅谈在JupyterNotebook下导入自己的模块的问题
2023-03-16 11:28:36
用python删除文件夹中的重复图片(图片去重)
2021-07-23 22:42:36
pandas多层索引的创建和取值以及排序的实现
2023-07-09 23:12:54
python和websocket构建实时日志跟踪器的步骤
2023-08-11 08:28:20
![](https://img.aspxhome.com/file/2023/7/115697_0s.gif)
Sql Server 字符串聚合函数
2024-01-17 08:15:34
python使用matplotlib的savefig保存时图片保存不完整的问题
2021-07-04 11:50:22
![](https://img.aspxhome.com/file/2023/3/134653_0s.png)
python如何实时获取tcpdump输出
2021-05-05 14:41:36
关于PyTorch中nn.Module类的简介
2023-03-19 13:31:15
vue 下列表侧滑操作实例代码详解
2024-04-30 10:19:36
![](https://img.aspxhome.com/file/2023/8/130288_0s.png)