You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过jQuery从指定ID的Bootstrap模态框中获取最新时间戳的TD数据

获取Bootstrap模态框表格中最新时间戳对应的评论内容

实现思路

遍历表格内的有效数据行(排除最后一行输入框所在行),将每行的时间戳转换为可比较的Date对象,筛选出时间戳最大的行,再提取该行的评论内容。

jQuery代码实现

// 定位模态框内表格的有效数据行(排除输入行)
const $dataRows = $('#QCPopUpMessageModal table tbody tr.warning');

let latestRow = null;
let latestTime = new Date(0); // 初始化为最早时间

$dataRows.each(function() {
    // 获取当前行的时间戳文本并转为Date对象
    const timeText = $(this).find('td:eq(2)').text().trim();
    const currentTime = new Date(timeText);
    
    // 对比时间,保留最新的行
    if (currentTime > latestTime) {
        latestTime = currentTime;
        latestRow = $(this);
    }
});

// 提取并使用最新评论
if (latestRow) {
    const latestComment = latestRow.find('td:eq(0)').text().trim();
    console.log(latestComment); // 示例中会输出"testing"
    // 此处可添加对评论的后续处理逻辑
}

代码说明

  • $('#QCPopUpMessageModal table tbody tr.warning'):精准筛选模态框内表格的有效数据行(输入行是tr.info,用tr.warning区分)。
  • 通过td:eq(2)获取每行第三列的时间戳,转成Date对象后完成时间对比,确保找到最新的记录。
  • 用td:eq(0)提取最新行的第一列评论内容,表格行动态增加时,代码依然能正确遍历所有有效行。

内容的提问来源于stack exchange,提问作者henrycharles

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 20:40:30