簡體   English   中英

IE6/7 中的 jKey jQuery 插件錯誤,每當按下任何未使用的鍵時都會嘗試運行。 如何戰斗?

[英]jKey jQuery plugin errors in IE6/7, attempting to run whenever any un-used key is pressed. How to combat?

我在當前項目中使用 jKey jQuery 插件。 它只允許您在按鍵上輕松運行 function。 這是我的 function 電話:

jQuery(document).jkey('left, right',function(key){
    if(key == 'left'){
        if (elementIndex == 0) { return; }
        question_nav(jQuery('.question-fieldset-active'), 'prev');
    } else {
        if ((elementIndex + 1) == jQuery('.question-fieldset').length) { return; }
        question_nav(jQuery('.question-fieldset-active'), 'next');
    }
});

在 IE6 和 7 中,按鍵盤上除左箭頭或右箭頭之外的任何其他鍵都會引發令人討厭的“錯誤消息:'indexOf' 是 null 或不是對象”錯誤。 有沒有辦法捕獲所有其他按鍵並返回; 在他們身上以避免這種情況?

實際上這是 jKey 本身的錯誤。 我在項目中嘗試使用時發現了這個錯誤。 這是將數組循環為 object 的經典問題:

: for(y in keySplit[x]) at GitHub revisionfor(y in keySplit[x]) at GitHub 修訂版

解決方案是將數組作為傳統循環遍歷:

for(var i = 0; i < keySplit.length; ++i)

所以你可以手動完成或從我的Google 代碼修訂版中獲取“jquery.jkey.js”的固定版本

而不是僅僅對key == 'right'使用else條件檢查,這可能會對您有所幫助。

jQuery(document).jkey('left, right',function(key){
    if(key == 'left'){
        if (elementIndex == 0) { return; }
        question_nav(jQuery('.question-fieldset-active'), 'prev');
    } else if(key == 'right') {
        if ((elementIndex + 1) == jQuery('.question-fieldset').length) { return; }
        question_nav(jQuery('.question-fieldset-active'), 'next');
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM