javascript - How to determine whether the value of src is empty?
ringa_lee
ringa_lee 2017-07-05 10:51:08
0
2
1003
<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?

ringa_lee
ringa_lee

ringa_lee

reply all(2)
为情所困

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template