如何在 d3 中获取变量属性

How to get variable attribute in d3

本文关键字:获取 变量 属性 d3      更新时间:2023-09-26

如何使用 d3 返回变量的特定属性?

例如,我想通过鼠标悬停来选择一个元素,并将选择传递给函数,但前提是元素的id是特定名称。

像这样的东西?

d3.select("body").on("mouseover", function(){ 
    if (d3.select(this).attr("id") == "correct") {
        enableInteraction(d3.select(this));
    }
});

是的。选择"this",然后使用常用函数访问属性。