获取/设置样式
obj.style(name,[value])
实质style里面是个json
obj.style({width:200,height:300px})
<!DOCTYPE html>
<html>
<head>
<title>d3</title>
<meta charset="utf-8">
<script src='node_modules/d3/d3.min.js'></script>
<style type="text/css">
.box p{
width: 100px;
height: 100px;
background: red;
}
</style>
<script type="text/javascript">
window.onload=()=>{
alert(d3.selectAll('p').style('width')) //100px
d3.selectAll('p').style('width','300px')
}
</script>
</head>
<body>
<div class="box">
<p>1111</p>
<p>2222</p>
</div>
</body>
</html>
注意json中key/value要打引号
window.onload=()=>{
alert(d3.selectAll('p').style('width')) //100px
d3.selectAll('p').style({
'background':'blue',
'width':'500px'
})
}