在HTML表被Javascript修改后读取它

Read HTML table after it has been modified by Javascript

本文关键字:读取 修改 Javascript HTML 表被      更新时间:2023-09-26

我目前正试图通读一个被JavaScript修改过的HTML表。我当前加载了一个HTML表,当我单击某个单元格时,该单元格中的单词会使用Javascript进行更改。我需要从被点击的表中获取所有行(单词从原始HTML加载中更改),当点击按钮时,一个新页面将打开,只显示"点击"的行信息。任何帮助都会很棒!!谢谢

您可以将data属性添加到点击处理程序中的单元格:

$('td').on('click', function() { 
  $(this).attr('data-original-text', $(this).text());
  // Do the rest of your manipulation here
});

点击的单元格会是这样的:

<td data-original-text="Text before the click">...</td>

收集按钮点击事件中的所有数据:

$('button').on('click', function() {
  $('td[data-original-text]').each() {
    // Serialize the values and send them off to the server
  });
});

或者您可以添加一个类,而不是数据属性

$('td').on('click', function() { 
  $(this).addClass('clicked');
  // Do the rest of your manipulation here
});

获取行并将其发送到服务器:

$('button').on('click', function() {
  $('tr:has(.clicked)').each(function() {
    // Serialize the values and send them off to the server
  });
});