我认为这是一个非常简单的问题,但我无法处理:我的 jsp 中有一个无序列表,其中包含一些列表项,例如:
<li>
<p class="text">Some text.</p>
<table class="answer-details" style="width: 100%">
<tbody>
<tr class="tr">
<td style="width: 50%;">
<div class="msg-modification" display="inline" align="right">
<a id="modify" class="delete-answer" href="#">Delete</a>
</div>
</td>
<td style="width: 50%; vertical-align: bottom;">
<img src="...">
<a class="answer-author" href="..." target="_blank">User name</a>
<div class="answer-info">29/06/2011</div>
</td>
</tr>
</tbody>
</table>
如您所见,每个列表项都有一个删除消息/答案的链接。我想要做的是,当我点击链接时,使用 jQuery 在同一个 li 中显示一条信息消息,并将除该消息之外的所有内容删除到列表项中。
这是我的 jQuery 代码:
$('.esborrar-resposta').click(function(event) {
event.preventDefault();
$(this).closest('.li').children('p').remove(); // it doesn't work
$(this).closest('.tr').before('<tr><td><div class="output">Information message</div></td></tr>');
$(this).closest('.tr').remove();
});
上面的代码删除了除段落标签之外的所有内容。这是我生成的 HTML 代码:
<li>
<p>Some text.</p>
<table class="answer-details" style="width: 100%">
<tbody>
<tr><td><div class="output">Information message</div></td></tr>
</tbody>
</table>
</li>
我想删除这个段落标签,但我尝试了这些选项但没有成功:
$(this).closest('.li').children('p').remove();
和
$(this).closest('.text').remove()
(也许它不起作用,因为段落标签不是链接标签的父级)
有人可以帮我删除它吗?