分类分类
更新时间:2026-02-18 21:01:26作者:fang
本文实例为大家分享了jquery实现删除一个元素后面的所有元素功能的详细实现过程,具体实现内容如下
实现效果:
选择项目

点击删除按钮,被选项之后的所有同级元素都被删除

jQuery 遍历的nextAll() 方法可以搜索 DOM 树中的元素跟随的同胞元素,也就是一个元素后面的所有同级元素,删除可以使用方法remove(),所以连起来为$(selector).nextAll().remove();
下面给出实例演示:点击按钮后,删除被选项目之后的所有选项
创建Html元素
<div class="box">
<span>点击按钮后,删除被选项目之后的所有选项。</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>
简单设置一下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();
});
})
以上就是小编为大家准备的知识点,希望大家可以熟练掌握。
相关
归墟战纪策略游戏262.92 MBv3.95802026-02-14
下载爆裂老奶策略游戏209.43 MBv1.0.112026-02-14
下载超能下蛋鸭策略游戏395.4 MBv1.2.82026-02-14
下载你好盒子实用工具12.1 MBv2.2.852026-02-14
下载我在峡谷当牛马休闲益智87.95 MBv0.7.12026-02-14
下载抽卡监狱2策略游戏190.75 MBv1.4.92026-02-14
下载Campus社交通讯94.36 MBv1.19.02026-02-14
下载冒险传奇角色扮演141.73 Mv9991.12026-02-14
下载心动次元app社交通讯43.96 Mv1.0.1.32026-02-14
下载致亲爱的我角色扮演1.63Gv1.02026-02-14
下载狼伴侣游戏手机版冒险游戏155.6 Mv1.02026-02-14
下载Loclike社交通讯169.08 Mv2.2.112026-02-14
下载










