当没有显示图像时,如何隐藏显示为“ https://www.underconsideration.com/brandnew/archives/google_broken_image_00_a_logo.gif ”的损坏图像图标?我使用 php 和 css 创建了一个评论框,允许用户发表评论以及上传照片。但是,如果用户只想发表评论而不上传任何照片,如果他们只发表评论而不上传任何照片,评论部分将显示损坏的图像图标。
我确实申请onError='this.style.display ='none';'
了alt=''
我的剧本,但仍然没有运气。
这是我编写的用于在用户发表评论或上传照片时显示评论和照片的代码:
function getComments($conn){
$sql = "SELECT * FROM comments";
$result = $conn->query($sql);
while ($row = $result->fetch_assoc()) {
echo "<div class = 'comment_box'><p>";
echo "<div class = 'comment_id'><p>";
echo $row['uid']."<br>";
echo "</p></div>";
echo "<div class = 'comment_date'><p>";
echo $row['date']."<br>";
echo "</p></div>";
echo "<div class = 'comment_msg fixed'><p>";
echo make_clickable(nl2br($row['message']));
echo "</p></div>";
echo "<div id='img_div'>";
echo "<img class='img_size' src='images/".$row['image']."' onError='this.style.display ='none';' alt='' />";
echo "</div>";
echo "</p>
<form class='delete-form' method='POST' action='".deleteComments($conn)."'>
<input type='hidden' name='cid' value='".$row['cid']."'>
<button type='submit' name='commentDelete'><img class='img_remove' src='img/remove.png'>REMOVE</button>
</form>
<form class='slash-form '>|
</form>
<form class='edit-form' method='POST' action='editcomment.php'>
<input type='hidden' name='cid' value='".$row['cid']."'>
<input type='hidden' name='uid' value='".$row['uid']."'>
<input type='hidden' name='date' value='".$row['date']."'>
<input type='hidden' name='message' value='".$row['message']."'>
<button><img class='img_change' src='img/change.png'>EDIT</button>
</form>
</div>";
}
}
图像图标损坏的问题发生在:
echo "<div id='img_div'>";
echo "<img class='img_size' src='images/".$row['image']."' onError='this.style.display ='none';' alt='' />";
echo "</div>";