jQuery:如何获取动态表的td值? [英] Jquery:How to get the dynamic table td value?

查看:576
本文介绍了jQuery:如何获取动态表的td值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的表格如下所示:

<tr class="A" id="A${a.index}"> //id is generic like 1,2,3,4,5  
    <table id="mytable">
        <tr>
           <td>a</td>
            <td>b</td>
         </tr>
         <tr>
            <td>c</td>
             <td>d</td>
      </tr>
       </table>
   </tr>

I am creating a generic table using  <tr> id, based on generic <tr> id  I'm trying to get the td value 

这是我尝试过的JS代码:

Here is the JS code I tried:

$('#mytable tr:nth-child(2) td').each(function(){
            alert($(this).text());
         });

上面的脚本将迭代第二个tr中的所有td值,但是我只需要基于我的父tr id值(我的tr id是动态的,它将一直在变化)就可以得到td值,我是Jquery的初学者,该表是通用表,因此我正面临一些困难,请问有人可以帮助我更正我的代码

The above script will iterate all the td value in second tr, but i need to get only td value based on my parent tr id value(my tr id is dynamic it will be always changing) ,i am beginner to Jquery ,this table is generic so i am facing some difficult , kindly Can somebody help me to correct my code

推荐答案

我认为这就是您想要的.检查表行列的文本是否与包含行ID的表相同

I think this is what you are looking for. Check whether the text of table row column is same as the table containing row id

$('#mytable tr:nth-child(2) td').each(function(){
    if($(this).text() === $("#mytable").parent().attr("id")) {
        alert($(this).text());
    }
});

这篇关于jQuery:如何获取动态表的td值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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