[英]Why browser refresh and close event detection is not working for IE and Safari
[英]function expression/event detection not working in ie<=9 or Safari
我一直在尋找答案的問題已有大約一天,但我有一個功能僅在IE9或更低版本或Safari中無法使用。 我認為這是因為它是由鍵盤事件觸發的。 它還將事件傳遞給函數,以便onkeyup函數可以檢查值並采取相應的措施。
我想知道是否有人可以啟發我解決問題所在,其功能如下:
window.onkeyup = function(e) { //This doesn't seem to work in the above browsers
var key = e.keyCode ? e.keyCode : e.which; //But neither does this
if (key == 83 && array.length>=0) {
// Log answer as 'S'
}else if (key == 68 && array.length>=0) {
//Log answer as 'D'
}
}
任何幫助,將不勝感激,謝謝。
可能是因為未在代碼中定義array
,因此至少在此部分的代碼中可見。 嘗試反轉條件,也許會起作用。
(e.which) ? e.which : e.keyCode
其他想法是在之前的比較中使用e
之前使用以下代碼:
if (window.event){
e = window.event.keyCode;}
else if (event.charCode) {
e = event.charCode;}
else if (event.which){
e = event.which; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.