【发布时间】:2015-10-26 16:56:27
【问题描述】:
我正在尝试将两个按钮添加到一个 div,一个在另一个下方。第一个按钮接受一个数字,第二个按钮用于打开和关闭线路。
只创建了我附加的第二个按钮。如何在同一个 div 中创建两个按钮?
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<script src="d3.js"></script>
<body>
<div id=options>
<script>
(function(){
var form = d3.select("#options")
.append("form")
.html("Enter a number:")
form.append("input")
.attr("type", "text")
.attr("name", "num")
form.append("input")
.attr("type", "button")
.attr("value", "Add")
.attr("onclick", "printNum(num.value)")
form.html("Show/hide lines:")
.append("input")
.attr("type", "button")
.attr("name", "toggle")
.attr("value", "Toggle")
.attr("onclick", "togglePressed()");
})();
function printNum(num){
alert("You entered " + num + "!");
}
function togglePressed(){
alert("You pressed the toggle button!");
}
</script>
</div>
</body>
</html>
【问题讨论】:
标签: javascript html css d3.js