尝试学习基本的javascript函数和html编码。
<!DOCTYPE html>
<html lang="en">
<head>
<script>
var bigHeart = new Image();
bigHeart.src = "vDay.jpg"
function goBig() {
document.heart.src = bigHeart.src
}
</script>
<meta charset="UTF-8">
<title>Big Heart</title>
</head>
<body>
<header onClick="goBig()"><img id="heart" src="vDay2">
</header>
</body>
</html>
当用户单击网页标题时,期望图像将与第二个图像交换。
最佳答案
我想你正在努力
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Big Heart</title>
<script>
function goBig() {
document.getElementById("heart").src = "new image path/url";
}
</script>
</head>
<body>
<header onClick="goBig()">
<img id="heart" src="old image path/url">
</header>
</body>
</html>