本文介绍了JavaScript密钥代码在Firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是JavaScript密钥代码,但它们不适用于Firefox,而是使用Chrome和IE浏览器。我在Firefox的前端调试了代码我得到的密码是 0
。
I am using JavaScript keycodes, they are not working in Firefox but working in Chrome and IE. I have debugged the code in front end for Firefox I am getting keycode as 0
.
这是我的代码:
$scope.Validate = function(event,indexVal){
if ((event.keyCode > 64 && event.keyCode < 91)|| (event.keyCode > 159 && event.keyCode < 166) || (event.keyCode > 96 && event.keyCode < 123) || (event.keyCode == 165) ||(event.keyCode == 32)
|| (event.keyCode == 164) || (event.keyCode == 130) || (event.keyCode == 181) || (event.keyCode == 144) || (event.keyCode == 214) ||
(event.keyCode == 224) ||(event.keyCode == 233)) {
}else{
event.preventDefault();
}
}
您能否建议一种方法来实现此功能Firefox也是。
Can you please suggest a way to achieve this functionality in Firefox too.
推荐答案
在Firefox中, event.keyCode
并不总是工作,取决于绑定事件。你必须使用 event.which
。有关详细信息,请参阅此。
In Firefox, event.keyCode
does not always work, depending on the binding event. You'll have to use event.which
. Refer to this post for more info.
$scope.Validate = function(event,indexVal) {
var key = event.keyCode || event.which;
if ((key > 64 && key < 91) ||
(key > 159 && key < 166) ||
(key > 96 && key < 123) ||
(key == 165) ||
(key == 32) ||
(key == 37) ||
(key == 39) ||
(key == 164) ||
(key == 130) ||
(key == 181) ||
(key == 144) ||
(key == 214) ||
(key == 224) ||
(key == 233)
) {
// Do something.
} else {
event.preventDefault();
}
}
这篇关于JavaScript密钥代码在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!