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

当我的删除按钮被点击时,我想将“is_active”输入的值从“是”更改为“否”。到目前为止,我试图使用兄弟姐妹来尝试选择具有“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>



RISEBY
浏览 74回答 1
1回答

蓝山帝景

我想通了,这是更新的代码:<script type="text/javascript">$(document).on("click", ".delete", function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ($(this).parents('.idcheck').length){&nbsp; &nbsp; &nbsp; &nbsp; $(this).closest('tr').find('.active').val('no');&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $(this).parents("tr").hide();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; {$(this).parents("tr").remove();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; $(".add-new").removeAttr("disabled");&nbsp; &nbsp; });</script>&nbsp;&nbsp;<table class="table table-bordered">&nbsp; &nbsp; <thead>&nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>First Name</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Last Name</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>County</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Street</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>City</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Ward</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Precinct</th>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <th>Actions</th>&nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; </thead>&nbsp; &nbsp; <tbody>&nbsp; &nbsp; <form id="" class="form" name="parts" method="post" action="">&nbsp; &nbsp; <tr class="idcheck">&nbsp; &nbsp; &nbsp; &nbsp; <td style="display:none;"><input type="hidden" class="form-control" name="username" id="username" value="user"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td><input type="text" class="form-control" name="first_name" id="first_name" value="John"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td><input type="text" class="form-control" name="last_name" id="last_name" value="Doe"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td><input type="text" class="form-control" name="county" id="county" value="my county"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td><input type="text" class="form-control" name="street" id="street" value="456 easy street"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td><input type="text" class="form-control" name="city" id="city" value="town"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td><input type="text" class="form-control" name="ward" id="ward" value="5"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td><input type="text" class="form-control" name="precinct" id="precinct" value="2"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td style="display:none;"><input type="hidden" class="form-control" name="id" id="id" value="1"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td style="display:none;"><input type="hidden" class="form-control active" name="is_active" id="is_active" value="yes"></td>&nbsp; &nbsp; &nbsp; &nbsp; <td><a class="delete" title="" data-toggle="tooltip" data-original-title="Delete"><i class="material-icons"></i></a>&nbsp; &nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; </tbody></table>我把这行改成了:$(this).siblings("td").next().find('.active').val('no');对此:$(this).closest('tr').find('.active').val('no');
打开App,查看更多内容
随时随地看视频慕课网APP