Jquery获取表格gridview中所有选中行的值 [英] Jquery get values of all checked rows in table gridview

查看:23
本文介绍了Jquery获取表格gridview中所有选中行的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张像下面这样的表格

I have a table like below

<table id="mytable">
<tr><th>checked</th><th>id</th><th>text</th></tr>
<tr><td><input id="cb1" type="checkbox" name="checker1"/></td><td>123</td><td>abc</td></tr>
<tr><td><input id="cb1" type="checkbox" name="checker1"/></td><td>456</td><td>def</td></tr>
<tr><td><input id="cb1" type="checkbox" name="checker1"/></td><td>789</td><td>ghi</td></tr>
</table>

我想检索(使用 jquery)表中所有已检查 ID 的 javascript 数组.

I want to retrieve (using jquery) a javascript array of all checked ID's in the table.

到目前为止,我有以下 jquery 代码,单击 jqcc 按钮会为每个选中的项目带来一个警报框,因此我需要检索第二个 td 的值,而不是警报,并将其添加到一个数组,

So far I have the following jquery code which on the click of the jqcc button brings me an alert box for each of the checked items, so instead of alert, i need to retrieve the value of the second td and add it to an array,

$(document).ready(function() {
    var tableControl= document.getElementById('mytable');
    $('#jqcc').click(function() {
        $('input:checkbox:checked', tableControl).each(function() {
            alert('checked');
        });
    });
});

推荐答案

你应该做的

$(document).ready(function() {
    var tableControl= document.getElementById('mytable');
   var arrayOfValues = [];
    $('#jqcc').click(function() {
        $('input:checkbox:checked', tableControl).each(function() {
            arrayOfValues.push($(this).closest('tr').find('td:last').text());
        }).get();
    });
});

arrayOfValues 将保存最后一个 td 内的文本.

arrayOfValues will hold the text inside the last td.

编辑当然你也可以使用地图

EDIT of course you could also use map

$(document).ready(function() {
    var tableControl= document.getElementById('mytable');
   var arrayOfValues = [];
    $('#jqcc').click(function() {
          arrayOfValues =  $('input:checkbox:checked', tableControl).map(function() {
            return $(this).closest('tr').find('td:last').text();
        });
    });
});

这篇关于Jquery获取表格gridview中所有选中行的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆