首页 > 代码库 > d3.js学习2

d3.js学习2

子选择器,在特定范围内选择元素


<section id="section1">	<div><h3>div1</h3></div></section><section id="section2">	<div><h3>div2</h3></div></section><script type="text/javascript">	d3.select("#section1 > div")	.style("border","2px solid blue");	d3.select("#section2")	.select("div")	.style("border","2px solid red");</script>

技术分享后代连接符 div span

子连接符 div > span 必须是严格的父子关系

函数级联调用(仅使用d3生成页面)


<script type="text/javascript">	var body = d3.select("body");	body.append("section")	.attr("id","section1")	.append("div")	    .style("border","2px solid blue")	.append("p")	    .text("be my valentine");	body.append("section")	.attr("id","section2")	.append("div")	    .style("border","2px solid red")	.append("p")	    .text("be my darling");</script>

  

 

d3.js学习2