jq里面remove()和empty()的区别
remove() - 删除被选元素(及其子元素)
empty() - 从被选元素中删除子元素
remove() 方法也可接受一个参数,允许对被删元素进行过滤。
该参数可以是任何 jQuery 选择器的语法。
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").remove(".italic");
});
});
</script>
</head>
<body>
<p>This is a paragraph in the div.</p>
<p class="italic"><i>This is another paragraph in the div.</i></p>
<p class="italic"><i>This is another paragraph in the div.</i></p>
<button>删除 class="italic" 的所有 p 元素</button>
</body>
</html>版权声明:本文由 LzxBlog 发布,如需转载请注明出处。







赞助云储存