巧用目标元素

 直接上代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
<body>
<div id="outer1" class = "haofa"style="background:#099">
<p class="inner" style="background:#9C0">click inner</p>
</div>
<div id="outer2" class = "haofa"style="background:#099">
<p class="inner" style="background:#9C0">click inner</p>
</div>
<div id="outer3" class = "haofa"style="background:#099">
<p class="inner" style="background:#9C0">click inner</p>
</div>
<div id="outer4" class = "haofa"style="background:#099">
<p class="inner" style="background:#9C0">click inner</p>
</div>
<div id="outer5" class = "haofa"style="background:#099">
<p class="inner" style="background:#9C0">click inner</p>
</div>
<div id="outer6" class = "haofa"style="background:#099">
<p class="inner" style="background:#9C0">click inner</p>
</div>

<script type="text/javascript">

$('.inner').click(function(e){
$('.haofa').has(e.target).remove();
})
</script>
</body>
</html>

......

通过$('.haofa').has(e.target).remove(),通过有无目标元素,找含有目标元素的父元素,从而删除;

posted @ 2016-11-08 16:59  ypm_wbg  阅读(118)  评论(0编辑  收藏  举报