Javascript 如何获取表格行id和该行的所有文本

Javascript 如何获取表格行id和该行的所有文本,javascript,jquery,Javascript,Jquery,单击“打印”按钮时,我需要获取表格行id以及与表格id关联的所有文本: 以下是我到目前为止的情况: JS: 图为: 试试这个: var tablid = $(this).parents('tr').attr('id'); var rowtext = $(this).closest('tr').text(); 此外,您还没有在单击调用中传递此对象引用。它应该是onclick=“SelectedRow(this)”: newContent+=Hesto.Html.CreateTD(“”,n

单击“打印”按钮时,我需要获取表格行id以及与表格id关联的所有文本: 以下是我到目前为止的情况: JS:

图为: 试试这个:

  var tablid = $(this).parents('tr').attr('id');
  var rowtext = $(this).closest('tr').text();
此外,您还没有在单击调用中传递此对象引用。它应该是
onclick=“SelectedRow(this)”

newContent+=Hesto.Html.CreateTD(“”,null);

我确实更改了它,但只显示了一个空的console.logoutputed@billah77:也尝试记录id。仍然没有发生任何事情。这是我现在拥有的函数SelectedRow(){var row=$(this)。parents('tr').attr('id');var rowtext=$(this)。closest('tr').text();console.log(rowtext);}@billah77:你能分享小提琴吗。
<table id="alternativeCableTable">
            <thead>
                 <tr>
                                    <th>Print</th>
                    <th>Common Cable</th>
                    <th>Wire Type</th>
                    <th>Wire Length</th>
                    <th>Terminal A</th>
                    <th>Seal A</th>
                    <th>Terminal B</th>
                    <th>Seal B</th>
                 </tr>
             </thead>
                <tbody id="AlternativeReworkCablesList">
             </tbody>
             <tfoot>
             </tfoot>
        </table>
function SelectedRow() {
        var row = $(this).parents('tr');
        var text = row.find('lineInfoRow').text();
        console.log(text);
}
  var tablid = $(this).parents('tr').attr('id');
  var rowtext = $(this).closest('tr').text();
 newContent += Hesto.Html.CreateTD('<input type="button" value="Print" id="btnprint" onclick="SelectedRow(this)">', null);