• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Sealgost
博客园    首页    新随笔    联系   管理    订阅  订阅
常用代码-03
表格操作

选中表格当前行:

代码:

$("body").on("click", "table > tr > td:nth-child(4)", function () {
    let currentRow = $(this).closest("tr");
    let currentRowtd01 = currentRow.find("td:eq(0)").text();
    let currentRowtd02 = currentRow.find("td:eq(1)").text();
    let currentRowtd03 = currentRow.find("td:eq(2)").text();
});
View Code

 

控制表格整体水平居中采用弹性布局

代码:

    /* product为该表格父元素 */
    #product {
        display: flex;
        justify-content: center;
    }
View Code

 

设置表格的表头或单元格内容对齐方式

代码:

    th {
        text-align: left;
        vertical-align: top;
    }

    td {
        text-align: left;
        vertical-align: bottom;
    }
View Code

 

选中表格某一行或列

代码:

    /* 选中某行 */
    tr:first-child {
        background-color: greenyellow;
    }

    tr:nth-child(3) {
        background-color: greenyellow;
    }

    tr:last-child {
        background-color: greenyellow;
    }

    /* 选中某列 */
    th:first-child,
    td:first-child {
        background-color: aqua;
    }

    th:nth-child(3),
    td:nth-child(3) {
        background-color: aqua;
    }

    th:last-child,
    td:last-child {
        background-color: aqua;
    }
View Code

 

选中表格奇数偶数行

代码:

    /* 除表头外的偶数行 */
    tr:nth-child(1)~tr:nth-child(even) {
        background-color: red;
    }

    /* 除表头外的奇数行 */
    tr:nth-child(1)~tr:nth-child(odd) {
        background-color: green;
    }
View Code

 

posted on 2023-04-23 15:54  Abagnate  阅读(28)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3