![](/img/trans.png)
[英]Selecting table elements and calculating total value using Jquery/Javascript
[英]Selecting a table data using javascript/jquery
嗨,我是javascript和jquery的新手,我只是想知道是否有任何方法可以使用這種格式選擇表數據:
$("#myTable").row[index1][index2];
其中index1是行索引,index2是列。 任何類似的東西也可以。
試試看:您可以在jQuery中使用.eq()遍歷具有指定索引的tr
和td
var td = $("#myTable").find('tr:eq('+index1+')').find('td:eq('+index2+')');
var data = $(td).text();// you can use .html() if you need html inside td
嘗試這個:
$(function(){
$('input').click(function()
{
var t= $(this).attr('class');
var text= $('.time'+t).text();
alert(text);
});
$('td').click(function()
{
var index = this.cellIndex;
alert($('tr:first').find('td').eq(index).text());
});
});
它將迭代您的表格單元並打印值-
$("#myTable>tr>td").each(function () {
var cell_value = $(this).html();
alert(cell_value);
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.