在Firefox中退格键的问题 [英] Backspace key issue in firefox
本文介绍了在Firefox中退格键的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,并应用允许字母与空间只使用jQuery。它在Chrome中工作但在Firefox中退格键不起作用。
< input type =textplaceholder = ID = ID1 >
$(function(){
$('#id1')。keypress(function(event){
if((event.which> = 65&& amp; (事件,其中事件>事件,其中事件> 96事件,事件<123) $ b return true;
}
else {
event.preventDefault();
}
})});
这是 Plnkr
解决方案
浏览器处理退格字符的方式有所不同。在Chrome中,退格键永远不会让它进入按键事件处理程序,但是在Firefox中却是这样。
如果添加 || event.which === 8
到你的条件,你将允许退格和返回true,这将使它在Firefox中工作。
I have an text box and applied Allow Alphabets With Space only using jquery. Its working in chrome But in firefox the backspace key is not working.
<input type="text" placeholder="" id="id1">
$(function(){
$('#id1').keypress(function (event) {
if ((event.which >= 65 && event.which < 91) || (event.which > 96 && event.which < 123) || event.which === 32 || event.which===0) {
return true;
}
else {
event.preventDefault();
}
})});
Here it is Plnkr
解决方案
It is a difference in how the browsers handle the backspace character. In Chrome, backspace never makes it to the keypress event handler, but in Firefox it does.
If you add || event.which === 8
to your conditional, you'll allow backspace and return true, which will get it working in Firefox.
这篇关于在Firefox中退格键的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文