gpt4 book ai didi

javascript - 删除之前的父元素

转载 作者:行者123 更新时间:2023-12-03 08:15:38 25 4
gpt4 key购买 nike

我需要 jquery 方面的帮助。我想要当插入<img class='deletework">删除标签<input type="text" hidden="true" value="1" required="true" name="countWorks"></input>来自文档。我尝试$('.deleteWork').click(function() { $(this).parent().parent().parent().parent().prev().remove(); });但这是行不通的。

<td align="center">
<b></b>
<input type="text" hidden="true" value="0" required="true" name="countWorks"></input>
<input type="text" hidden="true" value="1" required="true" name="countWorks"></input>
<table class="raw_inside2" width="100%" border="0" style="margin:0.3em 0.1em;">
<tbody>
<tr>
<th class="rowD" width="10%" title="Work types">
Work types
</th>
<th class="rowD" width="10%" title="Power">
Power
</th>
</tr>
<tr class="rowW">
<td>
<input type="text" value="Frezing" required="true" name="ManMnf"></input>
</td>
<td>
<input type="text" value="150" required="true" name="DSELbr"></input>
</td>
<td align="center">
<img class="deleteWork" title="Delete work type" src="../imglib/icon/del.gif"></img>
</td>
</tr>

最佳答案

尝试使用.closest().parent().find("input[name=countWorks]").eq(1)

$("img.deleteWork").click(function() {
$(this).closest("table").parent().find("input[name=countWorks]").eq(1)
.remove()
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td align="center">
<b></b>
<input type="text" hidden="true" value="0" required="true" name="countWorks" />
<input type="text" hidden="true" value="1" required="true" name="countWorks" />
<table class="raw_inside2" width="100%" border="0" style="margin:0.3em 0.1em;">
<tbody>
<tr>
<th class="rowD" width="10%" title="Work types">
Work types
</th>
<th class="rowD" width="10%" title="Power">
Power
</th>
</tr>
<tr class="rowW">
<td>
<input type="text" value="Frezing" required="true" name="ManMnf" />
</td>
<td>
<input type="text" value="150" required="true" name="DSELbr" />
</td>
<td align="center">
<img class="deleteWork" title="Delete work type" src="../imglib/icon/del.gif" />
</td>
</tr>
</tbody>
</table>
</tr>
</tbody>
</table>

关于javascript - 删除之前的父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33961911/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com