最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - document.onkeyup ported to jQuery - Stack Overflow

programmeradmin8浏览0评论

I'm porting some old Javascript to jQuery:

document.onkeyup = function (event) {
    if (!event) window.event;
    ...
}

this code works on all major browsers. My jQuery code looks like:

$(document).keyup = function (event) {
    ...
}

however this code is not working (the function is never triggered at least in IE7/8). Why? How to fix?

I'm porting some old Javascript to jQuery:

document.onkeyup = function (event) {
    if (!event) window.event;
    ...
}

this code works on all major browsers. My jQuery code looks like:

$(document).keyup = function (event) {
    ...
}

however this code is not working (the function is never triggered at least in IE7/8). Why? How to fix?

Share Improve this question asked Jun 26, 2009 at 15:08 dfadfa 116k32 gold badges192 silver badges229 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 17

The jQuery API is different:

$(document).keyup(function (event) {
    ...
});

jQuery.keyup is a function which takes as an argument the callback. The reason behind it is to let us assign multiple keyup (or whatever) events.

$(document).keyup(function (event) {
    alert('foo');
});

$(document).keyup(function (event) {
    alert('bar');
});

There's also keyup() without an argument, which will trigger the keyup event associated with the respective element.

发布评论

评论列表(0)

  1. 暂无评论