我正在尝试使用d3 selection获取offsetParent id (我以前也遇到过类似的问题,但由于某种原因,答案在这里不起作用)。
当我控制日志d3.select(this)时,日志是:
[Array[1]]
0: Array[1]
0: g
offsetParent: div#divID
id: "divID"
如何获取从d3.select(this)开始的id?
我想做的是:
d3.select(d3.select(this).select("g").node().offsetParent).attr("id")
但是get
Uncaught TypeError: Cannot read property 'offsetParent' of null
当它不为空时。我一定是选错了。
发布于 2015-10-23 00:06:44
G选项是导致问题的原因。此选项:
d3.select(d3.select(this).node().offsetParent).attr("id")
为我解决了这个问题。
https://stackoverflow.com/questions/33292471
复制