append string to image src using js

后端 未结 2 1103
南方客
南方客 2021-01-27 15:52

I\'ve got a page where there is \"\"

I want it so that upon loading of the page, the string \"?

相关标签:
2条回答
  • 2021-01-27 16:10

    Use this:

    window.onload = function() {
        document.getElementById('myImage').src += "/Action=thumbnail";
    };
    
    0 讨论(0)
  • 2021-01-27 16:14
    window.addEventListener('load', function(){
        /* assuming only one img element */
        var image = document.getElementsByTagName('img')[0];
    
        image.src += '?Action=thumbnail';
    }, false);
    

    Note, changing the source of the image will "re-fetch" the image from the server — even if the image is the same. This will be better done on the server-side.


    Update after comment:

    window.addEventListener('load', function(){
        /* assuming only one div with class "divclassname" and img is first child */
        var image = document.getElementsByClassName('divclassname')[0].firstChild;
    
        image.src += '?Action=thumbnail';
    }, false);    
    
    0 讨论(0)
提交回复
热议问题