[英]Image appearing when clicking a button
单击提交按钮时如何显示隐藏图像?
你很幸运我准备了一个空白的HTML页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<meta charset="utf-8" />
<title>Test</title>
<style type="text/css">
.hidden {
display: none;
}
</style>
</head>
<body>
<form>
<input type="submit" id="submit" onclick="document.getElementById('hidden').style.display = 'block';" />
</form>
<img id="hidden" class="hidden" src="foo.png" />
</body>
</html>
使用jQuery:
<img id="image1" src="myimage.jpg" style="display:none;" width="120" height="120"/>
<input type="submit" name="submit" value="submit" onclick"$('#image1').show()"/>
这取决于你如何隐藏它。 最简单的方法是将图像的类名从隐藏的图像更改为不隐藏图像的名称。
<img src="thesource" class="hidden">
document.getElementById("theid").className = ""; // remove the hidden class.
.classHidden {
display: none;
}
document.getElementById("submitBtn").onclick = function() {
document.getElementById("imageTag").style.display="block";
return true;
}
这是一个例子
<img class="image_file src="image.jpg" />
<input type="submit" id="submit_button" name="submit_button" />
在css中隐藏图像:
.image_file
{
display:none;
}
用jquery:
$('#submit_button').click(function(
$('.image_file').show();
));
并且尽量避免使用内联javascript,当你拥有一个大型网站时,它很难维护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.