小编rav*_*ger的帖子

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

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>
Run Code Online (Sandbox Code Playgroud)

我想要的是?当用户点击 input.editbox 时:

  • input.contentbox 变得可编辑
  • input.deletebox 变为未选中状态(如果之前已选中)

当用户点击 input.deletebox 时:

  • input.contentbox 被禁用
  • input.editbox 变为未选中状态(如果之前已选中)

我为那个结构做了这个:

<input type="checkbox" class="editbox"/>
<input type="text" class="contentbox" size="40" disabled="disabled"/>
<input type="checkbox" class="deletebox"/>
Run Code Online (Sandbox Code Playgroud)

通过使用 .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 () { …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-selectors

2
推荐指数
1
解决办法
6549
查看次数

标签 统计

jquery ×1

jquery-selectors ×1