在D3.js中selection.style和selection.attr之间有什么区别? [英] what's the difference between selection.style and selection.attr in D3.js?
本文介绍了在D3.js中selection.style和selection.attr之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现它们都在我的测试中工作:
I found both of them works in my test:
.on("mouseover",
function() {
d3.select(this)
.select("text")
.style("fill","red");
})
或
.on("mouseover",
function() {
d3.select(this)
.select("text")
.attr("fill","red");
})
推荐答案
您会看到类似的HTML:
If you look at the HTML you get, you'll see something like:
<text style="fill: red">...
和
<text fill="red">...
在SVG中都是合法的,但是当你需要风格的时候可以使用attr,如果你使用它为别的东西。
..which are both legal in SVG, but using attr when you need style could trip you up if you use it for something else.
这篇关于在D3.js中selection.style和selection.attr之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文