1
假設我們有這樣的代碼:event.altKey鉻無法正常工作和IE
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var p = 0;
function reset()
{
// some efforts
}
function code(e) {
e = e || window.event;
return(e.keyCode || e.which);
}
window.onload = function(){
document.onkeypress = function(e){
var key = code(e);
if(key == 38 || key == 40)
{}
else if(e.altKey)
{
alert('altkey pressed');
}
else
{
// Another THING!
}
};
};
</script>
</head>
<body style="padding:30px; font-size:30px;font-family: Courier;">
<span onclick="reset();" accesskey="r"></span>
</body>
</html>
在Firefox的偉大工程,但不是在IE瀏覽器的。
當我將alt
更改爲shift
時,它適用於所有瀏覽器。但正如你可能會注意到,我想用這個快捷鍵,我覺得這是在Chrome和IE Alt鍵關鍵的問題(因爲兩者都使用Alt鍵爲accesskey
屬性,但Firefox使用Alt鍵 + 移如mentally here)。
那麼你們建議我做什麼?
keyup對我更好。不管怎樣,謝謝。 – UltraDEVV 2014-09-20 19:37:09