Javascript 获取TD标记的特定值
如何在表中隐藏特定TD 呈现页面:Javascript 获取TD标记的特定值,javascript,jquery,asp.net,gridview,aspxgridview,Javascript,Jquery,Asp.net,Gridview,Aspxgridview,如何在表中隐藏特定TD 呈现页面: <table> <tr> <th>Codigo</th> <th>Tipo</th> <th>(L/V)</th> <th>Endereco</th> <th>Propostas Ativas</th> <th>Cons</th> <
<table>
<tr>
<th>Codigo</th>
<th>Tipo</th>
<th>(L/V)</th>
<th>Endereco</th>
<th>Propostas Ativas</th>
<th>Cons</th>
</tr>
<tr>
<td>373054</td>
<td>Apartamento</td>
<td>V</td>
<td>Rua DO FURQUIM</td>
<td>1</td>
<td>0</td>
</tr>
</table>
我想通过JQuery获取最后一列(Cons)的值,但用户看不到这一列。如何在每行中隐藏并获取此列的值?检查表的ID。假设它是
grdImoveis
,那么:
// Hide last column and and get its value (text)
var comp = $("#grdImoveis TD:last").hide().text();
假设您的Cons列始终是表中的最后一列,则应该这样做:
var myVar = '';
var myArray = new Array();
$('tr').each(function() {
//this fetches the text content of the last cell of the current row:
myVar = $(this).children("td:last").text();
//this puts that value at the end of the myArray array
myArray.push(myVar);
//this hides that td
$(this).children("td:last").hide();
});
我为它做了一个jsfiddle,似乎有用。
最简单的方法是:
$(document).ready(function(){
$('#<%=grdImoveis.ClientID %>').find('tr').each(function(){
$(this).find('td:last').hide();
});
});
但是,有了这段代码,网格中的最后一个数据将被隐藏。我想隐藏所有这列并获得每行的值
var myVar = '';
var myArray = new Array();
$('tr').each(function() {
//this fetches the text content of the last cell of the current row:
myVar = $(this).children("td:last").text();
//this puts that value at the end of the myArray array
myArray.push(myVar);
//this hides that td
$(this).children("td:last").hide();
});
$(document).ready(function(){
$('#<%=grdImoveis.ClientID %>').find('tr').each(function(){
$(this).find('td:last').hide();
});
});
var value= $(this).find('td:last').text();