JavaScript向div中添加数据,并删除的功能

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Bom练习</title>
<script type="text/javascript">
function removeButM(){
var xx = document.getElementById("addM");
xx.remove();
}
function removeButY(){
var xx = document.getElementById("addY");
xx.remove();
}
function removeButS(){
var xx = document.getElementById("addS");
xx.remove();
}
function removeButYY(){
var xx = document.getElementById("addYY");
xx.remove();
}
function removeButT(){
var xx = document.getElementById("addT");
xx.remove();
}




function addButM(){
var oo = document.createElement("input")
oo.value="美术      ✖";
document.getElementById("addAll").appendChild(oo); 
oo.setAttribute("type","button");
oo.setAttribute("onclick","removeButM()");
oo.setAttribute("id","addM")
var div1 = document.getElementById("addAll");  
  div1.appendChild(oo); 
}
function addButY(){
var oo = document.createElement("input")
oo.value="语文     ✖";
document.getElementById("addAll").appendChild(oo); 
oo.setAttribute("type","button");
oo.setAttribute("onclick","removeButY()");
oo.setAttribute("id","addY")
var div1 = document.getElementById("addAll");  
  div1.appendChild(oo); 
}
function addButS(){
var oo = document.createElement("input")
oo.value="数学      ✖";
document.getElementById("addAll").appendChild(oo); 
oo.setAttribute("type","button");
oo.setAttribute("onclick","removeButS()");
oo.setAttribute("id","addS")
var div1 = document.getElementById("addAll");  
  div1.appendChild(oo); 
}
function addButYY(){
var oo = document.createElement("input")
oo.value="英语     ✖";
document.getElementById("addAll").appendChild(oo); 
oo.setAttribute("type","button");
oo.setAttribute("onclick","removeButYY()");
oo.setAttribute("id","addYY")
var div1 = document.getElementById("addAll");  
  div1.appendChild(oo); 
}
function addButT(){
var oo = document.createElement("input")
oo.value="体育      ✖";
document.getElementById("addAll").appendChild(oo); 
oo.setAttribute("type","button");
oo.setAttribute("onclick","removeButT()");
oo.setAttribute("id","addT")
var div1 = document.getElementById("addAll");  
  div1.appendChild(oo); 
}





</script>
</head>
<body>
<div style="width: 400px;height: 300px;" id="addAll">
<input type="button" value="美术      ✖" οnclick="removeButM()" id="addM"/>
<input type="button" value="语文      ✖" οnclick="removeButY()" id="addY"/>
<input type="button" value="数学      ✖" οnclick="removeButS()" id="addS"/>
<input type="button" value="英语      ✖" οnclick="removeButYY()" id="addYY"/>
<input type="button" value="体育      ✖" οnclick="removeButT()" id="addT"/>
</div>
<input type="button" value="美术" οnclick="addButM()"/>
<input type="button" value="语文" οnclick="addButY()"/>
<input type="button" value="数学" οnclick="addButS()"/>
<input type="button" value="英语" οnclick="addButYY()"/>
<input type="button" value="体育" οnclick="addButT()"/>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值