<p class="section benefit-section cftx">
<img class="max-img" src="" alt="无图片">
<img class="max-img" src="" alt="无图片">
</p>
<script type="text/javascript">
window.onload = function() {
var imglength = document.getElementsByClassName("max-img");
alert(imglength[0].attribute("src"));
if (imglength[0].src == "") {
alert("空");
imglength[0].style.display = "none";
} else if (imglength[1].src === "") {
imglength[1].style.display = "none";
}
}
</script>
#img's src is read from the background, and the img is hidden when no image is uploaded in the background.
But in the case of src=" ", the content of the value is the path of the current web page.
How to change this judgment?
The src attribute value is set to get the current page URL. Location.href is to get the current address. Just add it directly to src
Give src a default value and hide it anyway