简体   繁体   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?

I'm using the jKey jQuery plugin on a current project.我在当前项目中使用 jKey jQuery 插件。 It just allows you to easily run a function on a key press.它只允许您在按键上轻松运行 function。 Here's my function call:这是我的 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');
    }
});

In IE6 and 7, pressing any other key on the keyboard besides the left or right arrows throws a nasty "Error Message: 'indexOf' is null or not an object" error.在 IE6 和 7 中,按键盘上除左箭头或右箭头之外的任何其他键都会引发令人讨厌的“错误消息:'indexOf' 是 null 或不是对象”错误。 Is there a way to capture all other key presses and return;有没有办法捕获所有其他按键并返回; on them so as to avoid this?在他们身上以避免这种情况?

Actually it's bug of jKey itself.实际上这是 jKey 本身的错误。 I've found this bug, when tried to use at the project.我在项目中尝试使用时发现了这个错误。 That was classic problem with looping through array as object:这是将数组循环为 object 的经典问题:

line 224 : for(y in keySplit[x]) at GitHub revision第 224 行for(y in keySplit[x]) at GitHub 修订版

The solution is to traverse array as traditional loop:解决方案是将数组作为传统循环遍历:

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

So u can do it manually or get fixed version of 'jquery.jkey.js' from my Google Code revision所以你可以手动完成或从我的Google 代码修订版中获取“jquery.jkey.js”的固定版本

Instead of just using else condition check for key == 'right' as well that might help you.而不是仅仅对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