Javascript 如何在d3中获取变量属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10309147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:47:37  来源:igfitidea点击:

How to get variable attribute in d3

javascriptd3.js

提问by Amyunimus

How do I return a specific attribute of a variable using d3?

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

For example, I want to select an element by mouseover, and pass on the selection to a function, but only if the element's idis a particular name.

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

Something like this?

像这样的东西?

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

回答by Lars Kotthoff

Yes. Select thisand then use the usual functions to access properties.

是的。选择this然后使用常用功能访问属性。