d3js 获取元素以及设置属性

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>D3JS 获取元素以及添加属性</title>
</head>
<body>
    <p>Hello World 1</p>
    <p>Hello World 2</p>
    <script src="https://cdn.bootcss.com/d3/4.13.0/d3.min.js" charset="utf-8"></script>
    <script type="text/javascript">
        d3.select("body").selectAll("p").text("mfg").style("color","red"); 
    </script>
</body>
</html>

 说明:

var p1 = body.select("p");

p1.style("color","red");
是选择第一个p

猜你喜欢

转载自www.cnblogs.com/mengfangui/p/9023368.html
今日推荐