当前位置:网站首页>Judging by JS in IE and edge, you can only enter numbers, letters and date types.
Judging by JS in IE and edge, you can only enter numbers, letters and date types.
2022-04-21 23:39:00 【Sheng Shaojun】
IE Of HTML:
ime-mode:disabled Restrict text entry , Only IE It works .
//ime-mode:disabled Restrict text entry , Only IE It works .
<input style="ime-mode:disabled" onkeypress="fncNum();return true;" />
IE Of JS : You can only enter Numbers , And press enter to convert to Tab.
keyCode48~57: Numbers ,keyCode13: enter ,keycode9:Tab.
//IE You can only enter Numbers , And press enter to convert to Tab.keyCode48~57: Numbers ,keyCode13: enter ,keycode9:Tab.
function fncNum() {
if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 13) {
event.returnValue = false;
} else if (event.keyCode == 13) {
event.keyCode = 9;
}
}
//IE Only numbers and negative numbers can be entered , And press enter to convert to Tab.
function fncMinusNum(obj) {
if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 13) {
if (event.keyCode != 45) {
event.returnValue = false;
}
} else if (event.keyCode == 13) {
event.keyCode = 9;
}
}
//IE You can only enter numbers and letters , And press enter to convert to Tab.
function fncAlphabetNum(obj) {
if (event.keyCode != 13 && !((event.keyCode >= 48 && event.keyCode <= 57) ||
((event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 97 && event.keyCode <= 122)))) {
event.returnValue = false;
} else if (event.keyCode == 13) {
event.keyCode = 9;
}
}
//IE Only numbers and numbers can be entered 「.」, And press enter to convert to Tab.
function fncDecimalScale(obj) {
if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 13 && event.keyCode !=46) {
event.returnValue = false;
} else if (event.keyCode == 13) {
event.keyCode = 9;
}
}
//IE Only numbers and numbers can be entered 「/」, And press enter to convert to Tab.
function fncDate(obj) {
if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 13 && event.keyCode != 47) {
event.returnValue = false;
} else if (event.keyCode == 13) {
event.keyCode = 9;
}
}
because ime-mode:disabled Only right IE Effective, so in Edge You need to add onkeyup Method .
//onkeyup Method ( You can only enter Numbers ).
<input style="ime-mode:disabled" onkeyup="this.value=this.value.replace(/\D/g,'')" onkeypress="fncNum();return true;" />
//onkeyup Method ( You can only enter numbers and letters ).
<input style="ime-mode:disabled" onkeyup="this.value=this.value.replace(/[^0-9,a-z,A-Z]/g,'')" onkeypress="fncNum();return true;" />
//onkeyup Method ( Only numbers and numbers can be entered 「-」 Minus sign ).
<input style="ime-mode:disabled" onkeyup="this.value=this.value.replace(/[^0-9,-]/g,'')" onkeypress="fncNum();return true;" />
//onkeyup Method ( Only numbers and numbers can be entered 「/」 Minus sign ).
<input style="ime-mode:disabled" onkeyup="this.value=this.value.replace(/[^0-9,/]/g,'')" onkeypress="fncNum();return true;" />
//onkeyup Method ( Only numbers and numbers can be entered 「.」 Minus sign ).
<input style="ime-mode:disabled" onkeyup="this.value=this.value.replace(/[^0-9,.]/g,'')" onkeypress="fncNum();return true;" />
keycode Add :
document.onkeydown in :
IE and Edge:keycode48~57: Numeric keypad above letters .keycode96~105: Right numeric keypad .
IE and Edge:keycode65~90: Lowercase and capital letters .
IE and Edge:keycode109,189: In negative numbers 「-」.
IE and Edge:keycode110,190: In decimals 「.」.
IE and Edge:keycode111,191: In the date 「/」.
input Of onkeypress in :
IE and Edge:keycode48~57: The numeric keypad above the letters and the numeric keypad on the right .
IE and Edge:keycode97~122: Lowercase letters .keycode65~90: Capital .
IE and Edge:keycode45: In negative numbers 「-」.
IE and Edge:keycode46: In decimals 「.」.
IE and Edge:keycode47: In the date 「/」.
If resources learn , You can like it and support it !
版权声明
本文为[Sheng Shaojun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212001485972.html
边栏推荐
- 自定義登錄成功處理
- 深度优先和广度优先的区别 笔记
- C language for complete square
- Buuctf question brushing record
- 7.10 thread condition variables
- Ijcai2022 employment results released! The acceptance rate is 15%. Did you win?
- JMeter association parameters
- Cuda02 - memory access optimization and unified memory
- How to set the motion stroke and angle in SolidWorks
- 341 Linux connection database
猜你喜欢

341-Linux 连接数据库

【acwing】1125. Cattle travel * * * (Floyd)

340 leetcode valid Letter ectopic words
![[express agent operation] how to do cross-border e-commerce in 2022? Express will focus on three things this year](/img/6b/f16f98d68b9519da67acf8fc8145e4.png)
[express agent operation] how to do cross-border e-commerce in 2022? Express will focus on three things this year

leetcode:386. 字典序排数

Pytorch中如何获取某层Module?(方便改变梯度,获取特征图,CAM等)

Leetcode:443 Compressed string

leetcode:443. 压缩字符串

7.3 创建线程

Connexion personnalisée traitée avec succès
随机推荐
红星美凯龙阵痛:“挥刀“降杠杆、净利率腰斩
BUUCTF 你(竟)然赶我走
JMeter association parameters
Golang force buckle leetcode 385 Mini parser
7.5 thread waiting for termination
341-Linux 连接数据库
File operation and IO
[express agent operation] how to do cross-border e-commerce in 2022? Express will focus on three things this year
【acwing】1125. Cattle travel * * * (Floyd)
Ijcai2022 employment results released! The acceptance rate is 15%. Did you win?
Difference between breadth first notes and breadth first notes
Prompt, can you do it or not?
7.4 线程退出
JDBC概念 在idea里创建JDBC项目步骤
341 Linux connection database
LeetCode_ 70 climb stairs
Buuctf Netherlands broadband data disclosure
Mobile app Games / software / resource download station / software box source code
C language for complete square
[fundamentals of interface testing] Part III differences between traditional style interfaces and restful style interfaces