HTML 中图片的隐藏与显示

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div id="axon">
<img src='../0.jpg' id='img1' class="axon" width="120px;" /><br />
<img src='../0(1).jpg' id='img2' class="axon" /><br />
<img src='../0(2).jpg' id='img3' class="axon" /><br />
</div>
</body>
<script type="text/javascript">
var Con = document.body;
var Re = /(<img\s+.*?>)/gi;
Con.innerHTML = Con.innerHTML.replace(Re, "<a onclick='ControlImg(this);'><span style='font-size:12px;color:blue;'><u>显示图片</u></span></a><span class='imgs' style='display:none'><br/>$1</span>");//这里的abc.com可以换成你要的网址
function ControlImg(nowEle) {
var nextEle = nowEle.nextSibling;
if (nextEle.style.display == "none") {
nowEle.innerHTML = "<span style='font-size:12px;color:blue;'><u>隐藏图片</u></span>";
nextEle.style.display = "block";
}
else {
nowEle.innerHTML = "<span style='font-size:12px;color:blue;'><u>显示图片</u></span>";
nextEle.style.display = "none";
}
}
</script>
</html>

posted @ 2013-10-31 16:51  Peter_youny  阅读(4094)  评论(0编辑  收藏  举报