添加删除

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.οnlοad=function(){
var oUl=document.getElementById('ul1');
var oTxt1=document.getElementById('txt1');
var oBtn=document.getElementById('btn1');
oBtn.οnclick=function(){
var oLi=document.createElement('li');
oLi.innerHTML=oTxt1.value+'<a href="javascript:;">删除</a>';
oLi.children[0].οnclick=function(){
oUl.removeChild(oLi);

}
if(oUl.children.length==0){
oUl.appendChild(oLi);
}else{
oUl.insertBefore(oLi,oUl.children[0]);

}
oTxt1.value='';
}
}
</script>
</head>
<body>
<input type="text" id="txt1">
<input type="button" value="添加" id="btn1">

<ul id="ul1">
</ul>
</body>
</html>

posted @ 2019-12-16 19:42  Cutelady  阅读(84)  评论(0编辑  收藏  举报