热门关键字:
jquery > jquery教程 > jquery教程 > 如何使用jQuery突出显示备用表格行

如何使用jQuery突出显示备用表格行

261
作者:管理员
发布时间:2021/2/5 11:55:34
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=3857
答:使用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
友荐云推荐