HTML按钮切换图像源 [英] HTML Button Change Image Source
本文介绍了HTML按钮切换图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,我想知道,这是可能的。
我想要一个形象,一个完全独立的按钮。当点击该按钮时,我想IMG SRC从图像/测试改为图像/ test2的
Okay, I was wondering if this is possible. I want an image, and a totally separate button. When the button is clicked, I would like the Img Src to change from "images/test" to "images/test2"
这可能吗?
让我们只说我有一个非常简单的网站,只有一个图像和一个按钮
Let's just say I have a very simple site, with just an image and a button
<html>
<head>...
</head>
<body>
<img src="images/test"/>
<br/><br/><br/>
<button>Click to change image!</button>
</body>
</html>
我怎样才能改变这种非常简单的HTML做我想要什么?
How can I change this very simple HTML to do what I want?
推荐答案
喜首先你 IMG
标签未在code关闭。
其次,你可以chnage使用简单的JavaScript或jQuery的按钮点击图像的src
。
Hi firstly you img
tag is not closed in your code.
Secondly you can chnage the image src
on click of the button using simple javascript or jQuery.
<html>
<head>
<script>
function changeImage()
{
var img = document.getElementById("image");
img.src="images/test2";
return false;
}
</script>
</head>
<body>
<img id="image" src="images/test" />
<br><br><br>
<button id="clickme" onclick="changeImage();">Click to change image!</button>
</body>
</html>
这篇关于HTML按钮切换图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文