x
 
<!DOCTYPE html>
<html>
<body>
<h1>演示如何访问 IMG 元素</h1>
<img id="myImg" src="/i/photo/tulip.jpg" alt="Tulip" width="300" height="300">
<p>单击该按钮可获取图像的 URL。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
  var x = document.getElementById("myImg").src;
  document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>