<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
.box{
width: 200px;
height: 200px;
background: red;
}
</style>
</head>
<body>
<button onclick='emptyFn()'>emptyFn</button>
<button onclick='removeFn()'>removeFn</button>
<div class="box">
<p>abc
<span>
abc
</span>
<span>
abc
</span>
</p>
<p>abc</p>
<p>abc</p>
<p>abc</p>
<p>abc</p>
</div>
</body>
</html>
<script src="./lib/jquery-3.4.1.js"></script>
<script type="text/javascript">
function emptyFn() {
// 删除当前元素下的所有子元素
$('.box').eq(0).empty();
}
function removeFn () {
$('.box').eq(0).remove();
}
</script>
jquery怎样移除所选节点下的所有子节点
最新推荐文章于 2022-05-16 19:38:55 发布