本文實例講述了JS動態修改圖片的URL(src)的方法。分享給大家供大家參考。具體如下:
下面的JS代碼可以動態修改圖片地址,以顯示一張新的圖片,實際上是通過修改圖片的src屬性來實現的
<!DOCTYPE html><html><head><script>function changeSrc(){document.getElementById("myImage").src="hackanm.gif";}</script></head><body><img id="myImage" src="compman.gif" width="107" height="98"><br><br><input type="button" onclick="changeSrc()" value="Change image"><p><b>Note:</b> The src property can be changed at any time. However, the new image inherits the height and widthattributes of the original image,if not new height and width properties are specified.</p></body></html>希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答