博客列表 >tab图片切换

tab图片切换

虾搞技术Home
虾搞技术Home原创
2019年03月29日 16:23:551513浏览

实例

<!DOCTYPE html>
<html>
<head>
	<meta charset="uft-8">
	<title>tab图片切换</title>
</head>
	<style>
		#box{
			width: 500px;
			height: 280px;
			margin: 0 auto;
			text-align: center;
			overflow: hidden;
		}
		span{
			display: inline-block;
			width: 80px;
			background-color: skyblue;
			border: 2px solid #999;
			margin-bottom: 5px;
			cursor: pointer;
		}
		img{
			width: 500px;
			height: 280px;
		}
	</style>
<body>
	<div id="box">
		<span onclick="fun(0)">切换1</span>
		<span onclick="fun(1)">切换2</span>
		<span onclick="fun(2)">切换3</span>
		<img src="images/1.jpg" alt="">
		<img src="images/2.jpg" alt="">
		<img src="images/3.jpg" alt="">
	</div>

	<script>
		function fun(x){
			var span = document.getElementsByTagName('span');
			var box = document.getElementById('bxo')
			var img =document.getElementsByTagName('img')
			for(var i=0;i<img.length;i++){
				img[i].style.display="none";
			}
			img[x].style.display="block";
		}
	</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议