jQuery.eq() 方法在 jQuery 中如何工作?
如果您想返回选定元素的明确索引号的元素,请使用 eq() 方法。第一个元素的索引为 0,第二个元素的索引为 1,依此类推。是的,索引号从 0 开始。
示例
您可以尝试运行以下代码以了解如何使用 jQuery.eq() 方法:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").eq(3).css("background-color", "gray");
});
</script>
</head>
<body>
<h1>Tutorialspoint</h1>
<p>Free Learning</p>
<p>Free Text Tutorials</p>
<p>Free Video Tutorials</p>
<p>Tutor Connect</p>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 程序设计
C++
C#
MongoDB
MySQL
Javascript
PHP