我使用JavaScript忽略文本框中的特殊字符。 但我需要允许箭头键操作。
所以,我允许
我的文本框中的键。
我使用以下函数,
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;
}
但是我发现这个键的另一个问题。
相同的导航键与特殊字符键相同。
这有什么不对?
如何限制在文本框中使用特殊字符[%,&amp;,',(]?