如何在 jQuery 中訪問元素的索引?
要訪問 jQuery 中元素的索引,請使用 eq() 方法。eq() 方法引用元素的位置。
示例
您可以嘗試執行以下程式碼以瞭解如何在 jQuery 中訪問元素的索引,
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('ul li').eq(2).css({'background-color':'#E6B16A'});});
</script>
</head>
<body>
<ul>
<li>India</li>
<li>US</li>
<li>UK</li>
<li>Australia</li>
</ul>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP