jquery动态增加的dom怎么绑定点击事件,新增的dom,点击无反应--用事件委托

<!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>jquery动态添加元素-事件绑定</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script type="text/javascript">
//事件绑定-事件委托
$(function(){
$("body").delegate('.wang', 'click', function(){
var addDom='<div class="wang" style="height: 20px; width: 30px; color:#fff;background:#333;">ddd</div>';
$(this).after(addDom);
});
});
</script>
</head>

<body>
<div class="wang" style="height: 20px; width: 30px; color:#fff; background:#333;">
1111
</div>

</body>
</html>

posted @ 2017-09-18 10:10  浩然正气  阅读(774)  评论(0编辑  收藏  举报