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

问题描述 投票:-1回答:1

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

这是我的代码:

<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>
javascript php jquery siblings
1个回答
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');
© www.soinside.com 2019 - 2024. All rights reserved.