jquery实现了删除元素后面所有元素的功能
本文分享了jquery删除元素后面所有元素的详细实现过程。具体实施内容如下。
达到效果:
选择权
点击删除按钮,选中后的所有同级元素都会被删除。
jQuery遍历的nextalall()方法可以在DOM树中搜索后面跟元素的兄弟元素,也就是一个元素后面的所有兄弟元素,而remove()方法可以用于删除,所以它们被链接为$(选择器)。nextalall()。移除();下面的示例演示:单击按钮后,删除所选项后的所有选项并创建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 ' Span小葱/Span br input type=' checkbox ' name=' item ' Span豆腐/Span input type=' checkbox ' name=' item ' Span土豆/Span input type=' item ' Span茄子/Span br/div input type=' button ' value=' delete '/div只需设置css样式即可。
div . box { width :300 px;高度:200 px;padding:10px 20pxborder:4px虚线# ccc} div . box span { color : # 999;font-style :斜体;} div . content { width :250 px;高度:100 px;margin 3 336010 px 0;border:1px纯绿色;}输入{ margin:10px} input[type=' button ']{ width :200 px;height:35pxmargin:10pxborder:2px实心# ebb cbbe;}编写jquery代码。
$(function(){ $(' input 3360 button '))。单击(function(){ $(' input : check box : checked ')。下一个()。nextAll()。移除();});})这些是边肖为大家准备的知识点。希望大家都能熟练掌握。
版权声明:jquery实现了删除元素后面所有元素的功能是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。