我是靠谱客的博主 高挑月光,这篇文章主要介绍jquery怎么从末尾移除一个元素,现在分享给大家,希望可以做个参考。

本教程操作环境:windows7系统、jquery3.6.1版本、Dell G3电脑。

jquery从末尾移除一个元素

方法1:“eq(-1)”选择器+remove()方法

  • 利用“eq(-1)”选择器从末尾选中最后一个元素

  • 使用remove()方法删除选中的元素

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-3.6.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("p").eq(-1).remove(); }); </script> </head> <body> <p>第一段</p> <p>第二段</p> <p>第三段</p> <p>第四段</p> <p>第五段</p> <p>第六段</p> </body> </html>
登录后复制

1.png

方法2:“:last”选择器+remove()方法

  • 利用“:last”选择器从末尾选中最后一个元素

  • 使用remove()方法删除选中的元素

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-3.6.1.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("p:last").remove(); }); </script> </head> <body> <html> <body> <p>第一段</p> <p>第二段</p> <p>第三段</p> <p>第四段</p> <p>第五段</p> </body> </html> </body> </html>
登录后复制

2.png

相关教程推荐:jQuery视频教程

以上就是jquery怎么从末尾移除一个元素的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是高挑月光最近收集整理的关于jquery怎么从末尾移除一个元素的全部内容,更多相关jquery怎么从末尾移除一个元素内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(148)

评论列表共有 0 条评论

立即
投稿
返回
顶部