jquery获取表格gridview中所有检查行的值 [英] Jquery get values of all checked rows in table gridview
本文介绍了jquery获取表格gridview中所有检查行的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张如下表格:
< table id =mytable>
< tr> th>第< th> id< th th> text< / th>< / tr>
< tr>< td>< input id =cb1type =checkboxname =checker1/>< / td>< td> 123< / td>< td> ; ABC< / TD>< / TR>
tr< td>< input id =cb1type =checkboxname =checker1/>< / td>< td> 456< / td>< td> ; DEF< / TD>< / TR>
< tr>< td>< input id =cb1type =checkboxname =checker1/>< / td>< td> 789< / td>< td> ; GHI< / TD>< / TR>
< / table>
我想检索(使用jquery)表中所有已检查ID的javascript数组。 p>
到目前为止,我有下面的jquery代码,它通过点击jqcc按钮为每个选中的项目带来一个警告框,所以不需要警报,我需要检索第二个td的值并将其添加到数组中,
$(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(){$ b $ arrayOfValues。 ($(this).closest('tr')。find('td:last')。text());
})。get();
});
});
arrayOfValues
td。
编辑当然你也可以使用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();
});
});
});
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>
I want to retrieve (using jquery) a javascript array of all checked ID's in the table.
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');
});
});
});
解决方案
You should do
$(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
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屋!
查看全文