admin管理员组文章数量:1430536
I am trying to extract the td values belonging a td rowspan.
<!DOCTYPE html>
<html>
<body>
<table border="1">
<tr>
<th>Month</th>
<th>Expenses</th>
<th>Exp/ Divided</th>
</tr>
<tr>
<td rowspan="2">January</td>
<td rowspan="2">$100</td>
<td>$50</td>
</tr>
<tr>
<td>$50</td>
</tr>
<tr>
<td rowspan="3">February</td>
<td rowspan="3">$400</td>
<td>$150</td>
</tr>
<tr>
<td>$150</td>
</tr>
<tr>
<td>$100</td>
<tr></tr>
</table>
</body>
</html>
So if I click on January for example I have to extract its divided expenses: $50, $50
if I click on February I have to extract its divided expenses: $150, $150, $100
I am trying to extract the td values belonging a td rowspan.
<!DOCTYPE html>
<html>
<body>
<table border="1">
<tr>
<th>Month</th>
<th>Expenses</th>
<th>Exp/ Divided</th>
</tr>
<tr>
<td rowspan="2">January</td>
<td rowspan="2">$100</td>
<td>$50</td>
</tr>
<tr>
<td>$50</td>
</tr>
<tr>
<td rowspan="3">February</td>
<td rowspan="3">$400</td>
<td>$150</td>
</tr>
<tr>
<td>$150</td>
</tr>
<tr>
<td>$100</td>
<tr></tr>
</table>
</body>
</html>
So if I click on January for example I have to extract its divided expenses: $50, $50
if I click on February I have to extract its divided expenses: $150, $150, $100
Share Improve this question edited Jan 27, 2014 at 6:18 Rohan Kumar 40.6k11 gold badges80 silver badges110 bronze badges asked Jan 27, 2014 at 6:11 Andy ChavesAndy Chaves 1472 gold badges2 silver badges10 bronze badges 1- 2 to be honest with you, i am plsql programmer, and don´t know this code , I just start reading some books, but my team ask me to plete this task by using JavaScript, but I am getting there, not yet, for now I just can ask for some help and learn – Andy Chaves Commented Jan 27, 2014 at 6:21
2 Answers
Reset to default 3Try this,
$(function(){
$('.rowspan').on('click',function(){
$tr=$(this).closest('tr');
rowspan=$(this).attr('rowspan');
index=$('tr').index($tr);
tot=parseInt(index)+parseInt(rowspan);
for(var i=index,len=tot;i<len;i++){
console.log($('tr:eq('+i+') td:last').text());
}
});
});
Working Demo
With jquery you can simply select the objects like so:
$("td[rowspan='2']");
To get the containing values it would be:
$("td[rowspan='2']").text();
More on this: http://api.jquery./attribute-equals-selector/
本文标签: javascriptHow to get Rowspan Rows Values with JS or jQueryStack Overflow
版权声明:本文标题:javascript - How to get Rowspan Rows Values with JS or jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745553067a2663033.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论