Javascript 为什么addEventListener函数会失败?

Javascript 为什么addEventListener函数会失败?,javascript,Javascript,我试图在addEventListener函数中使用一个对象一次分配多个事件。为什么不起作用 function $(id) { return document.getElementById(id); } $('t').addEventListener({ onclick: function() { alert('hi'); }, onmouseover: function() { alert('hey'); } }, tru

我试图在addEventListener函数中使用一个对象一次分配多个事件。为什么不起作用

function $(id) {
    return document.getElementById(id);
}

$('t').addEventListener({
    onclick: function() {
        alert('hi');
    },
    onmouseover: function() {
        alert('hey');
    }
}, true, false);

addEventListener
不支持多个事件。请参阅:

我有什么办法可以做到这一点吗?您可以,添加分离的监听器请调用它两次。或者使用jQuery。您可以编写一个函数来实现这一点。(或者使用jQuery的bind函数,但我假设您已经知道,因为您正在尝试复制相同的功能)