日期:2014-05-16 浏览次数:20333 次
<div id="ddd">
<div class="div1" >
<div class="div2">
<div class="div3">
<a>文本1</a>
</div>
<div class="div3">
<button class="button1">删除</button>
</div>
</div>
<div class="div2">
<div class="div3">
<a>文本2</a>
</div>
<div class="div3">
<button class="button1">删除</button>
</div>
</div>
<div>
<button class="add">添加div</button>
<script type="text/javascript">
//添加div
$(".add").click(function () {
var div = '<div class="div2"><div class="div3">自动添加的文本</div>' +
'<div class="commondivremove"><button class="button1">删除</button></div></div>';
$("#ddd").append(div);
});
//移除div
$("#ddd").on('click', 'button[class="button1"]', function () {
$("#ddd").remove();
});
</script>
$("#ddd button[class='button1']"
<!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 type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>