慕先生9164688
2019-03-22 22:56
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM的unwrap()方法</title>
<script src="D:\ChromeCoreDownloads\jquery-3.3.1.js"></script>
<style>
.left,
.right {
width: 250px;
height: 120px;
}
.left div,
.right div {
width: 100px;
height: 120px;
padding: 5px;
margin: 5px;
float: left;
border: 1px solid #ccc;
background: #bbffaa;
}
.right div {
background: yellow;
}
p {
border: 1px solid red;
}
a {
border: 1px solid blue;
}
</style>
</head>
<body>
<h2>DOM包裹unwrap()方法</h2>
<div class="left">
<div class="aaron1">点击,通过unwrap方法给p元素删除父容器div</div>
<div class="aaron2">点击,通过unwrap的回调方法给a元素删除父容器div</div>
</div>
<div class="right">
<div>
<p>p元素</p>
</div>
<div>
<p>p元素</p>
</div>
</div>
<div class="left">
<div>
<a>a元素</a>
</div>
<div>
<a>a元素</a>
</div>
</div>
<script type="text/javascript">
$(".aaron1").on('click', function() {
$('p').unwrap('<div></div>')
})
</script>
<script type="text/javascript">
$(".aaron2").on('click', function() {
$('a').unwrap(function() {
return '<div></div>';
})
})
</script>
</body>
</html>
可能是jq引用路径有问题
jQuery基础(二)—DOM篇
114012 学习 · 590 问题
相似问题