使用jQuery在类中选择一个元素

使用jQuery在类中选择一个元素,jquery,html,Jquery,Html,我做了一张带有for循环的桌子。像这样的东西当然不完全是我的代码 <table> for (int i = 0; i < 10; i++) { <tr> <td><label class='shutDownText'> Shutdown Time </label></td> <td><input type='time' class='selectShutdown'/> &

我做了一张带有for循环的桌子。像这样的东西当然不完全是我的代码

<table>
for (int i = 0; i < 10; i++)
{
    <tr>
    <td><label class='shutDownText'> Shutdown Time </label></td>
    <td><input type='time' class='selectShutdown'/> <input type='button' value='Accept'/></td>
    </tr>
}
</table>
你可能已经认识到我的问题了。每当我单击.Shutdown时,它都会更改.shutDownText中每个文本的文本。 如何仅选择同一标记中的一个元素


谢谢

使用jquery的最接近函数,它只选择像这样最接近的元素

$(document).ready(function ()
{
    $('.selectShutdown').change(function()
    {
        $(this).closest('.shutDownText').text($(this).val());
    });
});
您可以这样做:

$('.selectShutdown').change(function()
    {
        $(this).closest("tr").find('.shutDownText').text($(this).val());
    });
$('.selectShutdown').change(function()
    {
        $(this).closest("tr").find('.shutDownText').text($(this).val());
    });