0
代碼:N不承認
$(document).keydown(function(key) {
switch (parseInt(key.which, 10)) {
case 65:
$('img[src*="imgs/A1.png"]').remove();
break;
case 83:
$('img[src*="imgs/S1.png"]').remove();
break;
case 68:
$('img[src*="imgs/D1.png"]').remove();
break;
case 70:
$('img[src*="imgs/F1.png"]').remove();
break;
case 74:
$('img[src*="imgs/J1.png"]').remove();
break;
case 75:
$('img[src*="imgs/K1.png"]').remove();
break;
case 165:
$('img[src*="imgs/Ñ1.png"]').remove();
break;
default:
alert("key not found");
break;
}
});
我想,如果用戶按下正確的鍵刪除先前添加的圖像。它適用於「正常」字母,但不適用於「Ñ」。根據ASCII表格,相應的數字是165,但它不起作用(當我按下「Ñ」鍵時,它會提示「找不到密鑰」)。 任何想法?提前致謝。
'parseInt'不返回字符的ASCII/Unicode的價值。例如'parseInt(「A」,10)''返回'NaN'(不是數字)而不是65.您可能需要使用'key.which.charCodeAt(0)'。 – vstm
@vstm我認爲它確實如此。它適用於其他信件! – user2484181