html body tag,Does HTML 'body' tag have an onblur event?

问题

I tried to bind the onblur event to a

tag and it works in IE 6/8.

However, when I turn to w3schools, it turns out that the

tag doesn't have an onblur event.

Can anyone explain this?

回答1:

The HTML4 specification does not list the onblur attribute.

The HTML5 draft on the other hand does.

回答2:

body:onblur is part of the HTML5 spec, but not part of the HTML4 spec.

If you want to support HTML4 browsers, why not use window:onblur? For most cases, you'll have the same functionality.

回答3:

I would never rely on the source you mentioned. The problem is, MSIE fires the blur event for almost every element,

It might help if you explicitly the a tabIndex for the body element, for instance:

document.body.tabIndex = 1;

document.body.onblur = function() {

alert('body blur');

};

That works for me on FF5. That said, I'm not sure how many versions from FF and how much implementations support that 'tricky' workaround.

The next logical question is, why would you want to fire the body a blur event ? The only reasonable thing I can think of, is that you want to know when someone leaves your page ? If that is the case, I would recommend to watch the window itself instead of the body.

window.onblur = function() {

alert('window blur');

}

来源:https://stackoverflow.com/questions/6939047/does-html-body-tag-have-an-onblur-event

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值