Variable for img src=

前端 未结 2 869
滥情空心
滥情空心 2020-12-10 13:16

I have a question. Firstly, I am not going to pretend that I know what I am talking about here. I am a newbie to http and JavaScript.

I think my question may be ans

相关标签:
2条回答
  • 2020-12-10 14:04

    Yes, that page probably does answer your question. Basically, you want this javascript:

    <script type="text/javascript">
    document.getElementById('image').src = "yourpicture.png";
    </script>
    

    Except you want to replace the "yourpicture.png" with the function you wrote to generate the correct path to the image on disk, so...

    <script type="text/javascript">
    document.getElementById('image').src = displaydate();
    </script>
    

    Of course, you might need to modify this a bit for your own uses, the getElementById will take as an argument whatever the id attribute of your < img > tag is. You probably want to execute the above javascript after your page has loaded, i.e.:

    <html>
    <head>
    <script type="text/javascript">
    function load()
    {
    document.getElementById('image').src = displaydate();
    }
    
    function displaydate()
    {
    //your displaydate() function here
    }
    </script>
    </head>
    
    <body onload="load()">
    
    <img src="nothing.jpg" id="image" name="image"/>
    </body>
    </html> 
    
    0 讨论(0)
  • 2020-12-10 14:18

    You should just need to change this line

    document.write("http://host1/Shared/" + year + "/" + month + "/" + day + "/cpu_abs.gif");
    

    to

    return "http://host1/Shared/" + year + "/" + month + "/" + day + "/cpu_abs.gif";
    
    0 讨论(0)
提交回复
热议问题