Мне нужно получить идентификатор строки таблицы и весь текст, связанный с идентификатором таблицы, когда нажата кнопка печати: вот что я до сих пор: 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();
также вы не передали ссылку на объект в щелчке call.it должно быть onclick="SelectedRow(this)"
:
newContent += Hesto.Html.CreateTD('<input type="button" value="Print" id="btnprint" onclick="SelectedRow(this)">', null);