【发布时间】:2018-01-13 19:33:18
【问题描述】:
我创建了一个简单的事件脚本,当单击按钮时会更改图像。但不幸的是没有改变,请帮助。
错误:我也没有收到任何错误消息,只是它没有更改图像。
<html>
<head>
<title>Events Practise</title>
<style>
#imtest{
width:100px;
height:150px;
}
</style>
</head>
<body>
<h4> This a practise page of Events and event handlers </h4>
<p> Hi this the practise page that changes the Html and Css contents in the page by Using the JavaScript </p>
<img id="imtest" src="marni.jpg" alt="Image corrupted">
<button onclick="eventtest()">Change Image</button>
<script>
function eventtest()
{
var imt = document.getElementById("imtest");
imt.onclick = change;
}
function change()
{
var imtchng = document.getElementById("imtest");
imtchng.src = "marni1.png";
}
</script>
</body>
【问题讨论】:
标签: javascript button events dom-events