我不确定为什么我的点击方法不起作用。在此测试中,我希望能够单击图形上的一个圆形节点并显示其编号。悬停在某种作品上。
我正在使用哪个库的click事件,D3? jQuery的?普通的JS?
最终,当我将鼠标悬停在节点上时,我想做一些工具提示,当我将鼠标移开时,使它们消失
http://jsfiddle.net/ericps/b5v4R/
dots.enter()
.append("circle")
//.append("svg:circle")
.attr("class", "dot")
.attr("cx", complete_line.x())
.attr("cy", complete_line.y())
.attr("r",3.5)
.append("title")
.text(function(d){ return d.completed;})
.on("click", function(d) { alert("hello"); });
最佳答案
您已将事件处理程序附加到svg:text元素。我认为您想将其附加到svg:circle元素:
dots.enter().append("circle")
.attr("class", "dot")
.attr("cx", complete_line.x())
.attr("cy", complete_line.y())
.attr("r",3.5)
.on("click", function(d) { alert("hello"); })
.append("title")
.text(function(d){ return d.completed; });