function addItem() {
var newItem = document.createElement("div");
newItem.innerHTML = document.getElementById("box").value;
document.getElementById("list").appendChild(newItem);
}
input[type="text"] {
text-align: center;
font-size: 15px;
width: 200px;
height: 60px;
}
input[type="button"] {
text-align: center;
font-size: 15px;
width: 200px;
height: 60px;
}
<!DOCTYPE html>
<html>
<head>
<title>2-DO 2DAY</title>
</head>
<body>
<center>
<h1><font size="7" color="1E00FF">2-DO 2DAY</font></h1>
<br/>
<p><font size="8" color="5572FF"><em>What To Do Today?</em></font></p>
<br/>
<br/>
<input type="text" id="box" value="Click To Add Task"/>
<br/>
<br/>
<input type="button" value="Add Task" onclick="addItem();"/>
<br/>
<div id="list"></div>
</center>
</body>
</html>
基本上,这一切都是在按下我的按钮时,它从您输入的框中获取信息,然后将其添加到列表中。所以,是的,现在我将输入一堆随机单词,因为它说代码太多,单词不够。
一只名叫杰夫的 bat 飞进鲸脂里清理自己。
最佳答案
添加<br>
您的功能如下:
function addItem() {
var newItem = document.createElement("div");
newItem.innerHTML = document.getElementById("box").value + '<br><br>';
document.getElementById("list").appendChild(newItem);
}
我认为要实现你想要的效果,你实际上需要附加两个 <br>
s。还要注意正确使用中断标签。在 HTML 中,中断是 <br>
在 XHTML 中是 <br />
.
运行下面的代码片段以查看其实际效果。
function addItem() {
var newItem = document.createElement("div");
newItem.innerHTML = document.getElementById("box").value + '<br><br>';
document.getElementById("list").appendChild(newItem);
}
input[type="text"] {
text-align: center;
font-size: 15px;
width: 200px;
height: 60px;
}
input[type="button"] {
text-align: center;
font-size: 15px;
width: 200px;
height: 60px;
}
<center>
<h1><font size="7" color="1E00FF">2-DO 2DAY</font></h1>
<br/>
<p><font size="8" color="5572FF"><em>What To Do Today?</em></font>
</p>
<br/>
<br/>
<input type="text" id="box" value="Click To Add Task" />
<br/>
<br/>
<input type="button" value="Add Task" onclick="addItem();" />
<br/>
<div id="list"></div>
</center>
关于javascript - 我如何使这样的代码在添加到列表中的每个元素之间有中断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39185887/