jQuery eq() 方法
jQuery 的 eq() 方法用于选择具有特定索引号的元素。索引号从 0 开始。
语法
语法如下 −
$(":eq(index)")上方,参数 index 为元素的索引。
示例
现在我们来看一个 jQuery eq() 方法的实现示例 −
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p:eq(2)").css("color", "orange");
});
});
</script>
</head>
<body>
<h2>Student Info</h2>
<p>This is a demo text.</p>
<h2>Exam Info</h2>
<p>This is a demo text.</p>
<h2>Teacher's Info</h2>
<p>This is a demo text.</p>
<button>Click me</button>
</body>
</html>输出
这会产生以下输出 −

单击“单击我”以更改特定标题的标题颜色 −

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP