简体   繁体   English

如何使用 Javascript function 更改 HTML 代码中的图像?

[英]How do you change an image in HTML code using Javascript function?

   function partyimage() {
    var img = "https://clubrunner.blob.core.windows.net/00000050029/Images/party-time-logo.jpg";
    imaage.src = img;
}

 <div id="imaage">
    <img src="https://thumbs.dreamstime.com/b/funny-vector-stick-man-balloon-hat-children-s-style-no-party-event-sign-red-prohibition-stop-symbol-icon-sticker-156024993.jpg" alt="No Party right now" />
</div>

 window.onload =()=>{ var img = "https://clubrunner.blob.core.windows.net/00000050029/Images/party-time-logo.jpg"; let image = document.getElementById('imaage').childNodes[1]; image.setAttribute('src',img); }
 <div id="imaage"> <img src="https://thumbs.dreamstime.com/b/funny-vector-stick-man-balloon-hat-children-s-style-no-party-event-sign-red-prohibition-stop-symbol-icon-sticker-156024993.jpg" alt="No Party right now" /> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM