开发者

In JavaScript DOM, can it be determined if an element will listen for an event type? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Detecting support for a given JavaScript event?

having a random HTMLElement el, is开发者_运维问答 there anyway of knowing whether el can listen to an particular event type, for example, 'change'?


you can try checking if el.attributes.onchange is declared. I'm not sure, however, if dynamic changes to the webpage will be visible in this manner.


Yes, you can check it for a truthy value like this:

if (el.change) {
    el.change();
}

If the method exists you will be able to call it like this. You can check for any method in the manor before trying to call it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜