选择table中的第三行第三列

本文介绍了一个简单的HTML页面布局,包含一个使用红色边框的表格,并通过jQuery实现了按钮点击时改变表格显示的功能。代码中利用了$(document).ready()确保DOM加载完成后再绑定事件,通过点击带有bianse类名的按钮触发事件,进而遍历表格元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HTML部分

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        table tr td{
            border: 1px solid red;
        }
    </style>
</head>
<body>
<button class="bianse">变色</button>
<table>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
    </tr>
    <tr>
        <td>4</td>
        <td>5</td>
        <td>6</td>
    </tr>
    <tr>
        <td>7</td>
        <td>8</td>
        <td>9</td>
    </tr>
</table>
</body>
<script src="js/jquery.js"></script>
<script src="js/2.js"> </script>
<script >

</script>
</html>
$(document).ready(function () {
    $(".bianse").click(function () {
        $("table tr").each(function (index) {
            if(index == 2){
                console.log(index);
                $(this).find("td").each(function (index) {
                    if(index == 2){
                        console.log(index);
                      console.log($(this));
                    }
                })
            }
        })
    })
})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值