1 回答

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊
經(jīng)過(guò)長(zhǎng)時(shí)間搜索沒(méi)有結(jié)果,這是我的解決方案:(
適用于 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)"
>
在所有按鍵按下后執(zhí)行按鍵。
按下 18 (alt),通過(guò)將 altCapture 從 null 設(shè)置為 "" 開(kāi)始捕獲。
按下而不是 18 并捕獲,將數(shù)字附加到 altCapture。
(默認(rèn)情況下,不按下 18 且不捕獲。)
向上鍵 18,從代碼 altCapture 追加字符(+ 將字符串轉(zhuǎn)換為數(shù)字)。
(按鍵不是 18,默認(rèn)值。)
按鍵和捕獲,防止默認(rèn)值并將 altCapture 重置為 null。
(按鍵而不捕獲,默認(rèn)。)
添加回答
舉報(bào)