I'm using jKey but in IE8 i'm getting this error:
'length' is null or not an object
Whenever i press certain keys. It seems like whenever i press a key that doesn't exist yet (like if i never set anything up for a
it has the error message). But, I did setup a key command for enter
, but it's still doing it.
The code in question that's causing the error is:
if($.inArray(e.keyCode,keySplit[x]) > -1){
// Initiate the active variable
var active = 'unchecked';
// All the individual keys in the combo with the keys that are currently being pressed
for(y in keySplit[x]) {
if(active != false) {
if($.inArray(keySplit[x][y], activeKeys) > -1){
active = true;
}
else {
active = false;
}
}
}
The error happens on the first line. Knowing that keySplit[x]
returns a typeof
number
when nothing exists or if the key shortcut is only a single key, I add开发者_JAVA百科ed:
if(typeof(keySplit[x]) == 'number'){ keySplit[x] = [keySplit[x]]; }
Right above the code block above.
After that it sill worked in Chrome and FF, but still not IE. I also tried:
if(typeof(keySplit[x]) == 'number'){ keySplit[x] = new Array(keySplit[x]); }
if(typeof(keySplit[x]) == 'number'){ keySplit[x] = [keySplit[x].toString()]; }
if(typeof(keySplit[x]) == 'number'){ keySplit[x] = new Object(keySplit[x]); }
but none of them worked.The jQuery code that's causing the error is:
inArray: function( elem, array ) {
if ( indexOf ) {
return indexOf.call( array, elem );
}
for ( var i = 0, length = array.length; i < length; i++ ) {
if ( array[ i ] === elem ) {
return i;
}
}
return -1;
},
I think, your issue is related to another jKey bug. Check please my answer - you should use array like traversing in your implementation instead of associated.
精彩评论