Image srcProperty

Image 对象参考手册Image Object

Definition and Usage

The src property sets or returns the value of the src attribute of an image.

The src attribute specifies the URL of an image.

Syntax

imageObject.src=URL


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the src attribute.


Example

Example

<html>
<head>
<script>
function changeSrc()
  {
  document.getElementById("myImage").src="hackanm.gif.html";
  }
</script>
</head>
<body>

<img id="myImage" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSrc()" value="Change image">

</body>
</html>

Try it Yourself »


Image 对象参考手册Image Object Other Extensions