如何在分配函数后删除onmouseout事件? [英] How to remove the onmouseout event after having assigned a function?

查看:111
本文介绍了如何在分配函数后删除onmouseout事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我为一个onmouseout事件分配一个函数,但在运行该事件后,我需要删除它。

解决方案

这取决于你的代码,如果你用d3做了,那么你可以说

在您的onmouseout事件函数中:

  element.on ,func); 

function func(){
/ * do your stuff * /
element.on(mouseout,null);
}

如果你通过一个事件属性绑定事件,例如< div onmouseout =...> 那么你必须重构这个。在这种情况下,只需使用d3 on()函数来绑定事件。



多个处理程序到同一事件,可以使用命名空间:通过在事件中附加 .name ,您可以更具体地解决它们。


I have a problem, I'm assigning a function to the onmouseout event, but after running the event, I need to remove it. would greatly appreciate your help.

解决方案

This depends on your code, if you did this with d3, then you can say

inside your onmouseout event-function:

element.on("mouseout",func);

function func(){
    /*do your stuff*/
    element.on("mouseout",null);
}

If you bound the event via an event-attribute like <div onmouseout="..." > then you have to refactor this. In this case, simply use the d3 on() function to bind the event.

If you want to bind multiple handlers to the same event, you can use namespacing: By appending .name to the event, you can address them more specifically.

这篇关于如何在分配函数后删除onmouseout事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆