更改同级隐藏TD中的输入值

时间:2020-02-11 20:08:46

标签: javascript php jquery siblings

单击删除按钮后,我想将具有“活动”值类别的“ is_active”输入的值从“是”更改为“否”。 到目前为止,我尝试使用兄弟姐妹尝试选择“活动”类的输入。没有运气。

这是我的代码:

        ID TRANS_DT            KEEP_ID
---------- ------------------- -------
         2 01.08.2019 00:00:00 Y       
         3 01.09.2019 00:00:00 N       
         4 01.09.2019 00:00:00 Y   
.....

1 个答案:

答案 0 :(得分:0)

我知道了,这是更新的代码:

<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');
相关问题