1 回答

TA貢獻1895條經驗 獲得超7個贊
經過長時間搜索沒有結果,這是我的解決方案:(
適用于 0-65535 | 0000-ffff)
var altCapture = null;
function keydown(event) {
var keyCode = event.keyCode;
if(keyCode == 18) altCapture = "";
if(altCapture != null && keyCode != 18)
altCapture += (keyCode - 96);
}
function keyup(event) {
if(event.keyCode == 18) {
event.target.value += String.fromCharCode(+altCapture);
}
}
function keypress(event) {
if(altCapture != null) {
event.preventDefault();
altCapture = null;
}
}
<input
onkeydown ="keydown (event)"
onkeyup ="keyup (event)"
onkeypress ="keypress(event)"
>
<input
onkeydown ="keydown (event)"
onkeyup ="keyup (event)"
onkeypress ="keypress(event)"
>
在所有按鍵按下后執行按鍵。
按下 18 (alt),通過將 altCapture 從 null 設置為 "" 開始捕獲。
按下而不是 18 并捕獲,將數字附加到 altCapture。
(默認情況下,不按下 18 且不捕獲。)
向上鍵 18,從代碼 altCapture 追加字符(+ 將字符串轉換為數字)。
(按鍵不是 18,默認值。)
按鍵和捕獲,防止默認值并將 altCapture 重置為 null。
(按鍵而不捕獲,默認。)
添加回答
舉報