标签:d3js helloworld html javascript select
有兴趣的朋友欢迎来http://www.ourd3js.com/ 讨论
下面开始用D3.js处理第一个简单问题,先看下面的代码:
<html>
<head>
<meta charset="utf-8">
<title>HelloWorld</title>
</head>
<body>
<p>Hello World 1</p>
<p>Hello World 2</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>HelloWorld</title>
</head>
<body>
<p>Hello World 1</p>
<p>Hello World 2</p>
<script>
var paragraphs = document.getElementsByTagName("p");
for (var i = 0; i < paragraphs.length; i++) {
var paragraph = paragraphs.item(i);
paragraph.innerHTML = "I like dog.";
}
</script>
</body>
</html>
<html> <head> <meta charset="utf-8"> <title>HelloWorld</title> </head> <body> <p>Hello World 1</p> <p>Hello World 2</p> <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script> <script> d3.select("body").selectAll("p").text("www.ourd3js.com"); </script> </body> </html>
接下来改变字体的颜色和大小,如下:
var p = d3.select("body").selectAll("p").text("www.ourd3js.com"); p.style("color","red"); p.style("font-size","72px");可以看到上面的代码先给变量p赋值,再使用p。这样可以使代码更整洁。
[1] D3.js的HelloWorld,布布扣,bubuko.com
标签:d3js helloworld html javascript select
原文地址:http://blog.csdn.net/lzhlzz/article/details/27197993