我有一些这样的生成输出:
<figure>
<a href="location.php"><img src=""></a>
</figure>
当我应用这个 JS 时:
$(funciton() {
$('img').each(function(){
if($(this).attr('src') == null || $(this).attr('src') == '')
{
$(this).parent().remove();
}
});
它删除了 img 标签,它是一个标签的父标签,但在页面上留下了这个输出:
<figure>
"​"
</figure>
如何删除 paren't 的父标签或只是修剪它以便不存在空白实体?当图形标签中有任何内容时,它的高度和 css 的边距为 1px。我可以更改css,但想弄清楚这一点,非常感谢帮助!