可以适应不同的数量。
<!DOCTYPE html> <body> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <div id="enter"></div> <div id="exit"> <p></p> <p></p> <p></p> <p></p> <p></p> </div> </body> <script src="d3.v3.min.js" charset="UTF-8"></script> <script> var dataset = [3, 6, 9]; /* var enter = d3.select("#enter"); enter.selectAll("p") .data(dataset) .enter() .append("p") .text(function(d){return d;}); var exit = d3.select("#exit").selectAll("p"); var update = exit.data(dataset); var ext = update.exit(); update.text(function(d){return d;}); ext.remove(); */ var p = d3.select("body").selectAll("p"); var update = p.data(dataset); var enter = update.enter(); var exit = update.exit(); update.text(function(d){return d;}); enter.append("p").text(function(d){return d;}); exit.remove(); </script>
原文地址:https://www.cnblogs.com/aguncn/p/12388820.html
时间: 2024-10-10 01:49:36