jQuery-在td内选择输入(在同一行中)

jQuery-在td内选择输入(在同一行中),jquery,jquery-selectors,Jquery,Jquery Selectors,HTML结构: <tr> <td class="edit"><input type="checkbox" class="editbox" /></td> <td class="content"><input type="text" class="contentbox" size="40" disabled="disabled"/></td> <td class="delete"><input t

HTML结构:

<tr>
<td class="edit"><input type="checkbox" class="editbox" /></td>
<td class="content"><input type="text" class="contentbox" size="40" disabled="disabled"/></td>
<td class="delete"><input type="checkbox" class="deletebox" /></td>
</tr>
<input type="checkbox" class="editbox"/>
<input type="text" class="contentbox" size="40" disabled="disabled"/>
<input type="checkbox" class="deletebox"/>
但现在无法将jQuery代码转换为新结构。非常感谢您的帮助和建议。

尝试使用
parent()。查找(选择器)

在我看来,这是比下一个更好的解决办法。这一个更独立于html结构中的更改。您可以重新排列td中的复选框,代码仍然可以使用属性。

您可以使用
$(this)。使用
.find()
而不是使用
.next()
.prev()

$(document).ready(function () {
    $("#form input.editbox[type=checkbox]").each(function () {
        $(this).change(function () {
            if ($(this).is(":checked")) {
                $(this).next().removeAttr("disabled");
                $(this).next().next().attr('checked', false);
            } else {
                $(this).next().attr("disabled", "disabled");
            }
        });
    });
    $("#form input.deletebox[type=checkbox]").each(function () {
        $(this).change(function () {
            if ($(this).is(":checked")) {
                $(this).prev().attr("disabled", "disabled");
                $(this).prev().prev().attr('checked', false);
            }
        });
    });
});
$(document).ready(function () {
    $("#form input.editbox[type=checkbox]").each(function () {
        $(this).change(function () {
            if ($(this).is(":checked")) {
                $(this).parent().parent().find('.contentbox').removeAttr("disabled");
                $(this).parent().parent().find('.deletebox').attr('checked', false);
            } else {
                $(this).parent().parent().find('.contentbox').attr("disabled", "disabled");
            }
        });
    });
    $("#form input.deletebox[type=checkbox]").each(function () {
        $(this).change(function () {
            if ($(this).is(":checked")) {
                $(this).parent().parent().find('.contentbox').attr("disabled", "disabled");
                $(this).parent().parent().find('.editbox').attr('checked', false);
            }
        });
    });
});
$(document).ready(function () {
    $("#form input.editbox[type=checkbox]").each(function () {
        $(this).change(function () {
             var $tr =  $(this).closest('tr');
            if ($(this).is(":checked")) {
                $tr.find('.contentbox').removeAttr("disabled");
                $tr.find('.deletebox').attr('checked', false);
            } else {
                $tr.find('.contentbox').attr("disabled", "disabled");
            }
        });
    });
    $("#form input.deletebox[type=checkbox]").each(function () {
        $(this).change(function () {
            var $tr =  $(this).closest('tr');
            if ($(this).is(":checked")) {
                $tr.find('.editbox').attr("disabled", "disabled");
                $tr.find('.contentbox').attr('checked', false);
            }
        });
    });
});