<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title></head><body><input type="text" id="textt"><input type="button" value="添加" onClick="add()"><input type="button" value="删除" onClick="minus()"><ul id="namet"><li>刘德华</li></ul><script>var content=document.getElementById("textt");var aul=document.getElementById("namet");function add(){ if(content.value==""){ alert("请输入内容") }else{ var ali=document.createElement("li"); var text=aul.appendChild(ali); text.innerHTML=content.value;} content.value=" "; }function minus(){ }</script></body></html>
1 回答
晓梦Y分明
TA贡献1条经验 获得超2个赞
function minus(){
var source = document.getElementById('textt').value;
var target = document.getElementsByTagName('li');
for(var i = 0; i < target.length; i++){
if(source == target[i].innerHTML){
target[i].parentNode.removeChild(target[i]);
}
}
}
添加回答
举报
0/150
提交
取消