如何遍历表并读取每个行跨度中的第一个列 [英] How to loop through a table and read the first colum in every rowspan

查看:69
本文介绍了如何遍历表并读取每个行跨度中的第一个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jquery读取第一列的每个值?

How do I read each and every value of the first column using jquery?

我的代码无法正常工作.

I have the code which is not working.

$("foo:eq(1) tr").each(function(){
                alert(  $(this).find('td:first[rowspan]').text());
            });

 <table id="foo" border="1px"> 
    <tr>                      
      <td rowspan='3' id="date"> Monday5 </td> 
      <td id="Name">Jim </td> 
    </tr> 
    <tr>
       <td id="Name"> Remy </td>    
</tr>    
</table> 

推荐答案

在此处修复: http://jsfiddle. net/tes9E/4/

首先,jQuery :eq选择器是从零开始的.其次,您需要先按#键,然后再按ID进行选择,如下所示:

First, the jQuery :eq selector is zero-based. Secondly, you need to put a # before selecting by ids, like so:

 $("#foo:eq(0) tr").each(function(){
   alert( $(this).find('td:first[rowspan]').text() );
 });

来自jQuery文档:

From jQuery documentation:

.eq (索引)

索引-指示元素从0开始的位置的整数

index - An integer indicating the 0-based position of the element

否则,一切看起来都很棒.希望这会有所帮助!

Otherwise, everything looks great. Hope this helps!

这篇关于如何遍历表并读取每个行跨度中的第一个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆