I have the folling code, when it triggers the tab key is not working in firefox but works in chrome.
我有下拉代码,当它触发tab键不能在Firefox中工作但在chrome中工作。
HTML:
<input id="contactPhone" onkeypress="validationPhone(event)" data-bind='value: phone' type="text" class="form-control" maxlength='10'>
Here is the JS code:
这是JS代码:
validationPhone = function (x) {
var evt = window.event || x;
if ((evt.which > 46 && evt.which < 58) || evt.which == 8) {
return true;
}
else {
evt.preventDefault();
}
}
1 个解决方案
#1
0
you are using Javascript Char Code , You can use char code 9 for tab and Instead of onkeypress use onkeydown event
你正在使用Javascript Char Code,你可以使用char代码9作为tab而不是onkeypress使用onkeydown事件
Try With this :
试试这个:
HTML:
<input id="contactPhone" onkeydown="validationPhone(event)" data-bind='value: phone' type="text" class="form-control" maxlength='10'>
JS:
validationPhone = function (x) {
var evt = window.event || x;
if ((evt.which > 46 && evt.which < 58) || evt.which == 8 ||evt.which == 9) {
return true;
}
else {
evt.preventDefault();
}
}
#1
0
you are using Javascript Char Code , You can use char code 9 for tab and Instead of onkeypress use onkeydown event
你正在使用Javascript Char Code,你可以使用char代码9作为tab而不是onkeypress使用onkeydown事件
Try With this :
试试这个:
HTML:
<input id="contactPhone" onkeydown="validationPhone(event)" data-bind='value: phone' type="text" class="form-control" maxlength='10'>
JS:
validationPhone = function (x) {
var evt = window.event || x;
if ((evt.which > 46 && evt.which < 58) || evt.which == 8 ||evt.which == 9) {
return true;
}
else {
evt.preventDefault();
}
}