欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery實(shí)現(xiàn)刪除一個(gè)元素后面的所有元素功能

 更新時(shí)間:2015年12月21日 11:05:51   投稿:lijiao  
這篇文章主要介紹了jquery實(shí)現(xiàn)刪除一個(gè)元素后面的所有元素功能,操作簡(jiǎn)單方便,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了jquery實(shí)現(xiàn)刪除一個(gè)元素后面的所有元素功能的詳細(xì)實(shí)現(xiàn)過程,具體實(shí)現(xiàn)內(nèi)容如下

實(shí)現(xiàn)效果:

選擇項(xiàng)目

點(diǎn)擊刪除按鈕,被選項(xiàng)之后的所有同級(jí)元素都被刪除

jQuery 遍歷的nextAll() 方法可以搜索 DOM 樹中的元素跟隨的同胞元素,也就是一個(gè)元素后面的所有同級(jí)元素,刪除可以使用方法remove(),所以連起來為$(selector).nextAll().remove();
下面給出實(shí)例演示:點(diǎn)擊按鈕后,刪除被選項(xiàng)目之后的所有選項(xiàng)
創(chuàng)建Html元素

<div class="box">
 <span>點(diǎn)擊按鈕后,刪除被選項(xiàng)目之后的所有選項(xiàng)。</span><br>
 <div class="content">
 <input type="checkbox" name="item"><span>蘿卜</span>
 <input type="checkbox" name="item"><span>青菜</span>
 <input type="checkbox" name="item"><span>小蔥</span><br>
 <input type="checkbox" name="item"><span>豆腐</span>
 <input type="checkbox" name="item"><span>土豆</span>
 <input type="checkbox" name="item"><span>茄子</span><br>
 </div> 
 <input type="button" value="刪除">
</div>

簡(jiǎn)單設(shè)置一下css樣式

div.box{width:300px;height:200px;padding:10px 20px;border:4px dashed #ccc;}
div.box>span{color:#999;font-style:italic;}
div.content{width:250px;height:100px;margin:10px 0;border:1px solid green;}
input{margin:10px;}
input[type='button']{width:200px;height:35px;margin:10px;border:2px solid #ebbcbe;}

編寫jquery代碼

$(function(){
 $("input:button").click(function() {
 $("input:checkbox:checked").next().nextAll().remove();
 });
})

以上就是小編為大家準(zhǔn)備的知識(shí)點(diǎn),希望大家可以熟練掌握。

相關(guān)文章

最新評(píng)論