我是靠谱客的博主 清秀鲜花,这篇文章主要介绍jquery怎么选中前几个元素,现在分享给大家,希望可以做个参考。

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

jquery怎么选中前几个元素

:lt() 选择器选取 index 值小于指定数字的元素。

index 值从 0 开始。

最常见的用法:与其他选择器一起使用,选取指定组合中特定序号之前的元素(如上面的实例)。

相反的可使用 :gt selector 来选取 index 值大于指定数字的元素。

语法

复制代码
1
$(":lt(index)")
登录后复制

index 必需。规定要选择的元素。会选取 index 值小于指定数字的元素。

示例如下:

复制代码
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123</title> <script src="js/jquery.min.js"> </script> <script> $(document).ready(function(){ $("tr:lt(4)").css("background-color", "yellow"); }); </script> </head> <body> <h1>欢迎来到我的主页</h1> <table border="1"> <tr> <th>序号</th> <th>站点名</th> <th>网址</th> </tr> <tr> <td>1</td> <td>Google</td> <td>google.com</td> </tr> <tr> <td>2</td> <td>PHP</td> <td>uoften.com</td> </tr> <tr> <td>3</td> <td>Taobao</td> <td>taobao.com</td> </tr> <tr> <td>4</td> <td>Baidu</td> <td>baidu.com</td> </tr> <tr> <td>5</td> <td>Sina</td> <td>sina.com.cn</td> </tr> <tr> <td>6</td> <td>Facebook</td> <td>facebook.com</td> </tr> <tr> <td>7</td> <td>twitter</td> <td>twitter.com</td> </tr> <tr> <td>8</td> <td>youtube</td> <td>youtube.com</td> </tr> </table> </body> </html>
登录后复制

输出结果:

02.png

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

以上就是jquery怎么选中前几个元素的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是清秀鲜花最近收集整理的关于jquery怎么选中前几个元素的全部内容,更多相关jquery怎么选中前几个元素内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部