答:使用jQuery:nth-child()选择器
您可以使用jQuery:nth-child()选择器通过突出显示其替代行来创建斑马条纹表。该:nth-child(N)选择接受这些参数-每个孩子的指数相匹配(以出发1),字符串偶数或奇数,或者一个表达式(例如:nth-child(2),:nth-child(even),:nth-child(2n)让我们看一个例子:
例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Zebra Striped Table with jQuery</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
// Apply alt class on alternate table row
$("table tbody tr:nth-child(2n)").addClass("alt");
});
</script>
<style>
table{
如果您觉得本文的内容对您的学习有所帮助:
关键字:
jQuery