开发者

oninput/onkeyup/onkeydow/onpropertychange doesn't work in IE8

As you might have noticed from the title I'm trying to make an event work properly and IE is giving me a hard time. I have tried all possible combinations, none of them seems to work.

I'm trying to mimic the Google suggestions list. A visitor sho开发者_运维问答uld be able to come down in the list using the arrow keys, which is a Jquery keydown event. This event however also renders the request for the suggestion list at the same time in IE8 so the therefore the arrow keys function comes to an end (because of the request that is being maid.)

I know there must be a simple solution to this, but I can't see it.Help is appreciated. This is a demo: at jsbin

It works in all browsers but not in IE.


You are attaching the events before the elements exist.

Always work with elements only inside $(document).ready() method to be sure they exist and loaded in the document.

In your specific case, just move all the code:

el("inp").oninput=function(){
  addScript("http://www.google.nl/complete/search?callback=suggest&q="+this.value);
}

$('#inp').keydown(
function (e){
    var curr = $('#test').find('.current');
    //......
}
//.....

To be inside the $(document).ready( you already have.

Live test case that works for me in IE as well: http://jsfiddle.net/n7qAD/12/
(Your original code really didn't work in IE)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜