如何在创建的li元素和创建的button元素之间添加空间?
function createListElement(){
var li = document.createElement("li");
li.appendChild(document.createTextNode(input.value));
li.classList.add("space")
var Delete = document.createElement("button");
Delete.innerHTML="Delete";
li.appendChild(Delete);
Delete.addEventListener("click",function(e){
this.parentNode.parentNode.removeChild(this.parentNode);
})
ul.appendChild(li);
input.value = "";
li.addEventListener("click", linecross);
}
在按钮上留一些余量
function createListElement(){
var li = document.createElement("li");
var input =document.getElementsByTagName('input')[0];
var ul =document.getElementsByTagName('ul')[0];
li.appendChild(document.createTextNode(input.value));
li.classList.add("space")
var Delete = document.createElement("button");
Delete.innerHTML="Delete";
li.appendChild(Delete);
Delete.addEventListener("click",function(e){
this.parentNode.parentNode.removeChild(this.parentNode);
})
ul.appendChild(li);
input.value = "";
li.addEventListener("click", linecross);
}
function linecross(){
console.log('linecross');
}
createListElement();
button{
margin-left:200px;}
<input value=5/>
<ul></ul>