捕获 KeyCode 时的键盘错误声音
Posted
技术标签:
【中文标题】捕获 KeyCode 时的键盘错误声音【英文标题】:Keyboard Error Sound when catching KeyCode 【发布时间】:2013-10-25 14:42:32 【问题描述】:我正在使用捕获键盘输入的 javascript 进行编程,但问题是每次用户按下一个键时都会发出错误声音。我怎样才能禁用它?
【问题讨论】:
您介意向我们展示您捕获按键/按下事件的 JavaScript 代码吗? @Polaris878 给你↓ 【参考方案1】:@Polaris878
function KeyPressed(e)
if (!e) e = window.event;
if (e.which)
keycode = e.which
else if (e.keyCode)
keycode = e.keyCode
switch (keycode)
case 49:
key = "1";
break;
case 50:
key = "2";
break;
case 51:
key = "3";
break;
case 52:
key = "4";
break;
case 53:
key = "5";
break;
case 54:
key = "6";
break;
case 55:
key = "7";
break;
case 56:
key = "8";
break;
case 57:
key = "9";
break;
case 48:
key = "0";
break;
default:
key = "";
return false;
break
if (keys == "NULL")
keys = key
else
keys = keys + key
if (keys.length >= 5)
document.formular.submit();
document.formular.code.value = keys;
var keys = "";
document.onkeydown = KeyPressed
【讨论】:
以上是关于捕获 KeyCode 时的键盘错误声音的主要内容,如果未能解决你的问题,请参考以下文章