jquery问题,为什么新增的游戏不可以删除,但原来就在的可以删除
<!doctypehtml><htmllang="en"><head><metacharset="UTF-8"><title>游戏推荐</title><styletype...
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>游戏推荐 </title>
<style type="text/css" >
*{
margin:0px;
padding:0px;
font-size:12px;
}
#listbox{
margin:10px;
padding:15px;
border:1px solid #CCCCCC;
color:#0066FF;
}
dl{
display:block;
float:left;
margin:15px;
}
dd{
font-size:14px;
color:#663300;
}
dd a{
text-decoration:none;
font-size:14px;
color:#FF3300;
}
dd a:hover{
text-decoration:underline;
}
.clear{
clear:both;
height:0px;
}
</style>
</head>
<body>
<div id='listbox'>
<dl>
<dt><img src="images/p1.jpg" /></dt>
<dd>街机三国</dd>
<dd><a class='del' href='javascript:void(0);'>删除</a></dd>
</dl>
<dl>
<dt><img src="images/p2.jpg" /></dt>
<dd>霸域</dd>
<dd><a class='del' href='javascript:void(0);'>删除</a></dd>
</dl>
<dl>
<dt><img src="images/p3.jpg" /></dt>
<dd>斗破乾坤</dd>
<dd><a class='del' href='javascript:void(0);'>删除</a></dd>
</dl>
<div class='clear'></div>
<input type="button" value='新增游戏' class='add'/>
</div>
<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".add").click(function(){
var idx=Math.floor(Math.random()*4)+1;
var p="p"+idx;
var content="<dl><dt><img src=images/"+p+".jpg></dt><dd>新游戏</dd><dd><a class='del' href='javascript:void(0);'>删除</a></dd></dl>";
$(".clear").before(content);
})
$(".del").click(function(){
$(this).parent().parent().remove();
})
})
</script>
</body>
</html> 展开
<html lang="en">
<head>
<meta charset="UTF-8">
<title>游戏推荐 </title>
<style type="text/css" >
*{
margin:0px;
padding:0px;
font-size:12px;
}
#listbox{
margin:10px;
padding:15px;
border:1px solid #CCCCCC;
color:#0066FF;
}
dl{
display:block;
float:left;
margin:15px;
}
dd{
font-size:14px;
color:#663300;
}
dd a{
text-decoration:none;
font-size:14px;
color:#FF3300;
}
dd a:hover{
text-decoration:underline;
}
.clear{
clear:both;
height:0px;
}
</style>
</head>
<body>
<div id='listbox'>
<dl>
<dt><img src="images/p1.jpg" /></dt>
<dd>街机三国</dd>
<dd><a class='del' href='javascript:void(0);'>删除</a></dd>
</dl>
<dl>
<dt><img src="images/p2.jpg" /></dt>
<dd>霸域</dd>
<dd><a class='del' href='javascript:void(0);'>删除</a></dd>
</dl>
<dl>
<dt><img src="images/p3.jpg" /></dt>
<dd>斗破乾坤</dd>
<dd><a class='del' href='javascript:void(0);'>删除</a></dd>
</dl>
<div class='clear'></div>
<input type="button" value='新增游戏' class='add'/>
</div>
<script src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".add").click(function(){
var idx=Math.floor(Math.random()*4)+1;
var p="p"+idx;
var content="<dl><dt><img src=images/"+p+".jpg></dt><dd>新游戏</dd><dd><a class='del' href='javascript:void(0);'>删除</a></dd></dl>";
$(".clear").before(content);
})
$(".del").click(function(){
$(this).parent().parent().remove();
})
})
</script>
</body>
</html> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询