若依 js 中获取选中table行中userName的值
可以通过以下方式获取选中 table 行中 userName 的值:
- 使用 JavaScript 中的 DOM 操作来获取选中行的数据:
var table = document.getElementById("myTable"); // 假设表格的 id 是 myTable
var userName = table.rows[selectedIndex].cells[columnIndex].innerText;
其中,selectedIndex 是选中的行的索引,columnIndex 是 userName 列的索引。
- 使用 jQuery 来获取选中行的数据:
var userName = $("#myTable tr.selected td:eq(columnIndex)").text();
其中,selectedIndex 是选中的行的索引,columnIndex 是 userName 列的索引。需要在选中行的 tr 元素上添加一个类名 selected,以便在 jQuery 中选中该行。
以上两种方法都是基于表格的 HTML 结构进行操作,需要根据实际情况调整索引值和选择器
原文地址: http://www.cveoy.top/t/topic/iFfS 著作权归作者所有。请勿转载和采集!