js模拟删除父元素案例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			window.onload = function(){
				var btnS = document.querySelectorAll('button');
				btnS.forEach(function(item,idx){
					item.onclick = function(){
						//隐藏
						item.parentNode.style.display = 'none';
						// this.parentNode.style.display = 'none';
					}
				})
			}
		</script>
	</head>
	<body>
		<ul>
			<li>1231324242424 <button>删除</button> </li>
			<li>1231324265465 <button>删除</button> </li>
			<li>1231324765765 <button>删除</button> </li>
			<li>1231324765765 <button>删除</button> </li>
			<li>1231324765765 <button>删除</button> </li>
			<li>1231324765765 <button>删除</button> </li>
		</ul>
	</body>
</html>

 

posted @ 2020-12-24 09:20  JackieDYH  阅读(4)  评论(0编辑  收藏  举报  来源