如何通过JavaScript/jQuery获取和存储表中特定行的值

如何通过JavaScript/jQuery获取和存储表中特定行的值,javascript,jquery,Javascript,Jquery,如何在JavaScript/jQuery中的数组数组中存储表中每个选定行的值 要收听的事件(我想)应该是在单击“显示所选内容”按钮时 例如,在JS中,我们将有如下数组: result = [] result[0] = row1 result[0][1] = Gene value for row1 (Gene1) result[0][2] = Variant value for row1 (Variant1) result[0][7] = #5 value1 for row1 result[1]

如何在JavaScript/jQuery中的数组数组中存储表中每个选定行的值

要收听的事件(我想)应该是在单击“显示所选内容”按钮时

例如,在JS中,我们将有如下数组:

result = []
result[0] = row1
result[0][1] = Gene value for row1 (Gene1)
result[0][2] = Variant value for row1 (Variant1)
result[0][7] = #5 value1 for row1
result[1] = row2
result[1][1] = Gene value for row2 (Gene2)
etc
...
$("#show-selected").click(function () {
        var tr = $("tr");
        var array1 = [];
        tr.each(function(index1, trCurrent) {
            var array2 = [];
            var trChildrens = $(trCurrent).children();
            if(($(trChildrens[0]).children()[0]).checked){
                trChildrens.each(function(index2, trChildrensCurrent) {
                    var innerHtml = $(trChildrensCurrent).html();
                    array2.push(innerHtml);
                });
                array1.push(array2);
            }
        });
        console.log(array1);
    });

你可以这样做:

$("#show-selected").click(function () {
  var results =[];
  $(".variants-table-tbody tr").each(function (index,item) {
      if($(item).find('[name="select-item"]').prop("checked")){
        results.push([
            [$(item).find("td").eq(1).text()],
            [$(item).find("td").eq(2).text()],
            [$(item).find("td").eq(3).text()],
        ]);
      }
  });
  console.log(results);
});
这将以您描述的格式在选中的行上创建数据。
请参见以下内容:

result = []
result[0] = row1
result[0][1] = Gene value for row1 (Gene1)
result[0][2] = Variant value for row1 (Variant1)
result[0][7] = #5 value1 for row1
result[1] = row2
result[1][1] = Gene value for row2 (Gene2)
etc
...
$("#show-selected").click(function () {
        var tr = $("tr");
        var array1 = [];
        tr.each(function(index1, trCurrent) {
            var array2 = [];
            var trChildrens = $(trCurrent).children();
            if(($(trChildrens[0]).children()[0]).checked){
                trChildrens.each(function(index2, trChildrensCurrent) {
                    var innerHtml = $(trChildrensCurrent).html();
                    array2.push(innerHtml);
                });
                array1.push(array2);
            }
        });
        console.log(array1);
    });
测试: