如何在JavaScript中忽略带有箭头键的特殊字符?

如何在JavaScript中忽略带有箭头键的特殊字符?,javascript,Javascript,我使用JavaScript忽略文本框中的特殊字符。 但我需要允许箭头键操作 所以,我允许 左=37 上升=38 右=39 向下=40 我的文本框中的键 我为此使用以下函数 function checkKeys(event){ // Getting the event to be triggered. var theEvent = event || window.event; // Getting the type of event or code. var key = theEvent.k

我使用JavaScript忽略文本框中的特殊字符。 但我需要允许箭头键操作

所以,我允许

  • 左=37
  • 上升=38
  • 右=39
  • 向下=40
我的文本框中的键

我为此使用以下函数

function checkKeys(event){
 // Getting the event to be triggered.
var theEvent = event || window.event;
// Getting the type of event or code.
var key = theEvent.keyCode || theEvent.which;

// Check with list of code and ignore holding.
// Tab, Space, Home, End, Up, Down, Left, Right...
if (key === 9 || key === 32 || key === 13 || key === 8 || (key >= 35 && key <= 40)) { //TAB was pressed
    return true;
}

// If not in list then check return with corresponding data.
key = String.fromCharCode(key);
// Return also if length is 0.
if (key.length == 0) return true;

// Finally return "false" for general keys.
return false;
}
功能检查键(事件){
//正在获取要触发的事件。
var theEvent=event | | window.event;
//获取事件或代码的类型。
var key=theEvent.keyCode | | theEvent.which;
//检查代码列表并忽略保持。
//制表符,空格,起始,结束,上,下,左,右。。。

如果(键===9 | |键===32 | |键===13 | |键===8 | | | | |键>=35&&key使用
event.key
event.shiftKey
来区分它们。这不允许操作键(如“那是”?。event.shiftKey不允许操作键!
event.shiftKey
不禁止任何东西,它只是一个对象键。