单击打印按钮时,我需要获取表行ID和与该表ID相关联的所有文本:
这是我到目前为止所拥有的:
JS:

newContent += Hesto.Html.StartTR(item.CommonCable, 'lineInfoRow');
            newContent += Hesto.Html.CreateTD('<input type="button" value="Print" id="btnprint" onclick="SelectedRow()">', null);
            newContent += Hesto.Html.CreateTD(item.CommonCable, null, null);
            newContent += Hesto.Html.CreateTD(item.Wire, null, null);
            newContent += Hesto.Html.CreateTD(item.WireLength * 1000, null);
            newContent += Hesto.Html.CreateTD(item.TerminalA, null);
            newContent += Hesto.Html.CreateTD(item.SealA, null);
            newContent += Hesto.Html.CreateTD(item.TerminalB, null);
            newContent += Hesto.Html.CreateTD(item.SealB, null);
            newContent = Hesto.Html.EndTR(newContent);
        });

        $('#AlternativeReworkCablesList').html(newContent);
    }


HTML:

<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>


JS功能:

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();


您也没有在点击调用中传递对象引用,它应该为onclick="SelectedRow(this)"

 newContent += Hesto.Html.CreateTD('<input type="button" value="Print" id="btnprint" onclick="SelectedRow(this)">', null);

关于javascript - 如何获取表的行ID和该行的所有文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23609576/

10-16 13:11
查看更多