调用$(this)里面的元素? [英] Call elements inside $(this)?

查看:63
本文介绍了调用$(this)里面的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在元素中查找元素

我正在运行一个循环来遍历每个表格行。我想访问每个表行内的元素。我该怎么做?

Im running a loop to go through each table row. I want to access the elements inside each table row. How do I do this?

表:

<table>
<tr> <td class="a">x</td> <td class="b">x</td> <td class="c">x</td> </tr>
<tr> <td class="a">x</td> <td class="b">x</td> <td class="c">x</td> </tr>
<tr> <td class="a">x</td> <td class="b">x</td> <td class="c">x</td> </tr>
<tr> <td class="a">x</td> <td class="b">x</td> <td class="c">x</td> </tr>
</table>

代码无效:

$("tr").each(function(index) {

    // get class a text
    $(this + " td.a").text();

    // get class b text
    $(this + " td.b").text();

    // get class c text
    $(this + " td.c").text();

});


推荐答案

你可以使用 children 方法:

You can use children method:

$("tr").each(function(index) {

    // get class a text
    var text1 = $(this).children("td.a").text();

    // get class b text
    var text2 = $(this).children("td.b").text();

    // get class c text
    var text2 = $(this).children("td.c").text();

});

这篇关于调用$(this)里面的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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