更改兄弟隐藏 TD 中的输入值

Change value of input in sibling hidden TD

单击我的删除按钮时,我想将具有 'active' 的 class 值的 "is_active" 输入的值从 "yes" 更改为 "no"。 到目前为止,我尝试使用兄弟姐妹来尝试 select 输入 'active' 的 class。运气不好。

这是我的代码:

<script type="text/javascript">
$(document).on("click", ".delete", function(){

         if ($(this).parents('.idcheck').length){

        $(this).siblings("td").next().find('.active').val('no'); 
        $(this).parents("tr").hide();

         }
        else 
        {$(this).parents("tr").remove();
        }

        $(".add-new").removeAttr("disabled");

    });
</script>  

<table class="table table-bordered">
    <thead>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>County</th>
            <th>Street</th>
            <th>City</th>
            <th>Ward</th>
            <th>Precinct</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
    <form id="" class="form" name="parts" method="post" action="">
    <tr class="idcheck">
        <td style="display:none;"><input type="hidden" class="form-control" name="username" id="username" value="user"></td>
        <td><input type="text" class="form-control" name="first_name" id="first_name" value="John"></td>
        <td><input type="text" class="form-control" name="last_name" id="last_name" value="Doe"></td>
        <td><input type="text" class="form-control" name="county" id="county" value="my county"></td>
        <td><input type="text" class="form-control" name="street" id="street" value="456 easy street"></td>
        <td><input type="text" class="form-control" name="city" id="city" value="town"></td>
        <td><input type="text" class="form-control" name="ward" id="ward" value="5"></td>
        <td><input type="text" class="form-control" name="precinct" id="precinct" value="2"></td>
        <td style="display:none;"><input type="hidden" class="form-control" name="id" id="id" value="1"></td>
        <td style="display:none;"><input type="hidden" class="form-control active" name="is_active" id="is_active" value="yes"></td>
        <td><a class="delete" title="" data-toggle="tooltip" data-original-title="Delete"><i class="material-icons"></i></a>
        </td>
    </tr>
    </tbody>
</table>

我明白了,这是更新后的代码:

<script type="text/javascript">
$(document).on("click", ".delete", function(){

         if ($(this).parents('.idcheck').length){

        $(this).closest('tr').find('.active').val('no'); 
        $(this).parents("tr").hide();

         }
        else 
        {$(this).parents("tr").remove();
        }

        $(".add-new").removeAttr("disabled");

    });
</script>  

<table class="table table-bordered">
    <thead>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>County</th>
            <th>Street</th>
            <th>City</th>
            <th>Ward</th>
            <th>Precinct</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
    <form id="" class="form" name="parts" method="post" action="">
    <tr class="idcheck">
        <td style="display:none;"><input type="hidden" class="form-control" name="username" id="username" value="user"></td>
        <td><input type="text" class="form-control" name="first_name" id="first_name" value="John"></td>
        <td><input type="text" class="form-control" name="last_name" id="last_name" value="Doe"></td>
        <td><input type="text" class="form-control" name="county" id="county" value="my county"></td>
        <td><input type="text" class="form-control" name="street" id="street" value="456 easy street"></td>
        <td><input type="text" class="form-control" name="city" id="city" value="town"></td>
        <td><input type="text" class="form-control" name="ward" id="ward" value="5"></td>
        <td><input type="text" class="form-control" name="precinct" id="precinct" value="2"></td>
        <td style="display:none;"><input type="hidden" class="form-control" name="id" id="id" value="1"></td>
        <td style="display:none;"><input type="hidden" class="form-control active" name="is_active" id="is_active" value="yes"></td>
        <td><a class="delete" title="" data-toggle="tooltip" data-original-title="Delete"><i class="material-icons"></i></a>
        </td>
    </tr>
    </tbody>
</table>

我更改了行:

$(this).siblings("td").next().find('.active').val('no');

为此:

$(this).closest('tr').find('.active').val('no');