d3.js on“click”事件处理运行功能没有点击事件 [英] d3.js on "click" event handling running function without click event

查看:2984
本文介绍了d3.js on“click”事件处理运行功能没有点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前为我的d3可视化执行鼠标单击事件处理:

I'm currently doing mouse click event handling for my d3 visualization:

fooCircle.on("click",fooFunction("barParameter"));

我的问题是函数运行时没有我必须单击元素。我知道这是因为我把打印语句放在函数中。

My problem is that the function is ran without me having to click on the element. I know this because I put print statements within the function.

有趣的是,当我将函数改为不是一个接受任何参数的函数时,函数行为应该,这意味着当我点击相应的元素时,它会运行:

Interestingly, when I change the function to not be a function that takes in any parameters, the function behaves has it should, meaning it gets ran when I click on the appropriate element:

fooCircle.on("click",fooFunction);


推荐答案

有人帮我解决了这个问题。解决方案是:

Someone helped me with the problem. The solution is do:

fooCircle.on("click", function () {fooFunction("barParameter"); });

这样,函数传递到on函数,而不是函数的结果。

This way, a function is passed into the on function, as opposed to the result of a function.

这篇关于d3.js on“click”事件处理运行功能没有点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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