jQuery eq() 方法
jQuery 的 eq() 方法用於選擇具有特定索引號的元素。索引號從 0 開始。
語法
語法如下 −
$(":eq(index)")上方,引數 index 為元素的索引。
示例
現在我們來看一個 jQuery eq() 方法的實現示例 −
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/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