我是靠谱客的博主 坚定火龙果,这篇文章主要介绍jquery怎么去除第一个元素,现在分享给大家,希望可以做个参考。

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

jquery去除第一个元素

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

  • 利用“eq(0)”选择器获取第一个元素对象

  • 使用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
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#but1").click(function() { $("p").eq(0).remove(); }); }); </script> </head> <body> <p>第一段</p> <p>第二段</p> <p>第三段</p> <p>第四段</p> <p>第五段</p> <p>第六段</p> <button id="but1">删除第一个元素</button> </body> </html>
登录后复制

1.gif

方法2:“:first”选择器和remove()方法

  • 利用“:firs”选择器获取第一个元素对象

  • 使用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
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <script src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#but1").click(function() { $("p:first").remove(); }); }); </script> </head> <body> <p>第一段</p> <p>第二段</p> <p>第三段</p> <p>第四段</p> <p>第五段</p> <p>第六段</p> <button id="but1">删除第一个元素</button> </body> </html>
登录后复制

2.gif

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

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

最后

以上就是坚定火龙果最近收集整理的关于jquery怎么去除第一个元素的全部内容,更多相关jquery怎么去除第一个元素内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部