获得TD标签的具体价值
问题描述:
如何在我的表中隐藏特定的TD?获得TD标签的具体价值
呈现的页面:
<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>
ASP页:
<asp:GridView ID="grdImoveis" Width="100%" runat="server" AutoGenerateColumns="false" DataSourceID="dsGrid" OnRowDataBound="grdImoveis_DataBound">
<Columns>
<asp:BoundField HeaderText="Código" DataField="Imovel_Id" />
<asp:BoundField HeaderText="Tipo" DataField="TipoDsc1" />
<asp:BoundField HeaderText="(L/V)" DataField="TransacaoSigla" />
<asp:TemplateField HeaderText="Endereco">
<ItemTemplate>
<%# Eval("Descricao") %> <%# Eval("Logradouro") %>, <%# Eval("Numero") %> - <%# Eval("Expr1") %> <%# Eval("Complemento") %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Propostas Ativas" DataField="NumeroProposta" />
<asp:BoundField HeaderText="Cons" DataField="FoundInSanNegocio" />
</Columns>
</asp:GridView>
图(例):
Código Tipo (L/V) Endereço Propostas Ativas Cons
373054 Apartamento V Rua Do Furquim 1 0
我想通过JQuery拿到最后一列的值(缺点),但用户无法看到此列。我怎样才能在每一行中隐藏和获取这列的价值?
答
最简单方法是:
$(document).ready(function(){
$('#<%=grdImoveis.ClientID %>').find('tr').each(function(){
$(this).find('td:last').hide();
});
});
要获得点击或其他一些事件的价值,你可以使用:
var value= $(this).find('td:last').text();
答
检查你的表的ID是什么。假设它的grdImoveis
,则:
// Hide last column and and get its value (text)
var comp = $("#grdImoveis TD:last").hide().text();
答
假设你的缺点列一直是你的表的最后一个,这应该这样做:
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它,似乎工作。 http://jsfiddle.net/qnvHM/
但是,与此代码,刚刚过去的数据在我的网格将被隐藏起来。我想隐藏所有这一列,并获得每一行的值 – 2012-03-02 14:52:01