Blogger Information
Blog 250
fans 3
comment 0
visits 321064
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jquery元素和元素内容的删除操作
梁凯达的博客
Original
936 people have browsed it

jquery元素和元素内容的操作方法主要有:

1、remove():用于删除掉整个元素

2、empyt():用于删除掉元素的内容部分

知识点补充:

filter():方法将匹配的元素集合缩减到指定的元素范围

//

代码部分

<!DOCTYPE html>

<html>


<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>Document</title>

</head>

<style type="text/css">

.buttonyellow {

background: yellow;

}


.buttongreen {

background: green;

}

</style>


<body>


<ul>

<li>

<a href="">这是一个a标签</a>

</li>

<li>

<a href="">这是一个a标签</a>

</li>

<li>

<a href="">这是一个a标签</a>

</li>

<li>

<a href="">这是一个a标签</a>

</li>

<li>

<a href="">这是一个a标签</a>

</li>

<li>

<a href="">这是一个a标签</a>

</li>

<li>

<a href="">这是一个a标签</a>

</li>

<li>

<a href="">这是一个a标签</a>

</li>

</ul>

<button>removr操作删除元素</button>

<button>empty操作删除内容</button>

</body>

<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript">

//方法1:remove():用于删除掉整个元素

//备注:方法filter(),用于将匹配元素集合缩减到指定的元素

$('button').eq(0).on('click',function(){

$('li').filter('.buttonyellow').remove()

})

//方法2:empty():用于删除掉元素的内容部分,仅删除内容但保留了元素

$('button').eq(1).on('click',function(){

$('li').filter('.buttongreen').empty()

})

</script>


</html>


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!