删除事件侦听器

时间:2015-12-29 01:00:01

标签: javascript

如果我将事件处理程序添加到

之类的事件中
select ym.year, ym.month, d.division, d.department,
       coalesce(Payments_received_Count, 0) as Payments_received_Count
from divisions d cross join
     (select distinct year, month from payments) ym left join
     payments p
     on d.division = p.division and d.department = p.department and
        ym.year = p.year and ym.month = p.month
order by year desc, month desc, division, department;

如何删除上述样式中添加的事件处理程序。

我尝试使用如下所示的removeEventListener,但它没有用。

HTMLElement.onclick = somefunction;

我该怎么办?

2 个答案:

答案 0 :(得分:5)

如果您使用onclick分配方法,则需要将onclick重新分配给其他值以“取消绑定”它,例如:

HTMLElement.onclick = null;

请注意,虽然使用onclick被认为是不好的做法,因为它不允许您绑定多个功能,而是更喜欢addEventListener

答案 1 :(得分:2)

addEventListenerremoveEventListener

一起使用

实施例

HTMLElement.addEventListener('click', somefunction)
HTMLElement.removeEventListener('click', somefunction)