Blogger Information
Blog 20
fans 0
comment 0
visits 25259
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
javascript实现tab标签改变图片效果
左手Leon的博客
Original
621 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Js实现tab标签切换</title>
	<style type="text/css">
		*{margin:0;padding:0;}
		div{width: 506px;height:400px;margin:50px auto;overflow: hidden;}
		li{list-style: none}
		#tab_list{text-align: center;height: 40px;line-height: 40px;border-bottom: none;}
		#tab_list li{float:left;width: 100px;height:40px;border: 1px solid #ccc;border-right: none;cursor: pointer;}
		#tab_list li:last-of-type {
                border-right: 1px solid #ccc;
            }
        #tab_list li:hover {
                background: #ccc;
            }   

		img{width: 510px;height: 360px;}
		/*p span{
			display: inline-block;
			width: 20px;
			height: 20px;
			text-align: center;
			background: rgba(254,254,254,0.3);
			border-radius: 50%;
			line-height: 20px;
			cursor: pointer;
		}*/
	</style>
</head>
<body>
	<div>
		<ul id="tab_list">
			<li onmouseover="change(0)">1</li>
			<li onmouseover="change(1)">2</li>
			<li onmouseover="change(2)">3</li>
			<li onmouseover="change(3)">4</li>
			<li onmouseover="change(4)">5</li>
		</ul>
		<!-- <p>
		<span onclick="change(0)">1</span>
		<span onclick="change(1)">2</span>
		<span onclick="change(2)">3</span>
		<span onclick="change(3)">4</span>
		<span onclick="change(4)">5</span>
		</p> -->
		<ul class="tab_img">
			<li><a href=""><img src="static/images/1.jpg" alt=""></a></li>
			<li><a href=""><img src="static/images/2.jpg" alt=""></a></li>
			<li><a href=""><img src="static/images/3.jpg" alt=""></a></li>
			<li><a href=""><img src="static/images/4.jpg" alt=""></a></li>
			<li><a href=""><img src="static/images/5.jpg" alt=""></a></li>
		</ul>
	</div>
	<script>
		function change(num){
			var obj=document.getElementsByClassName('tab_img')[0];
			var obj_li=obj.getElementsByTagName('a');
			// document.getElementById('tab_list').getElementsByTagName('li')[num].style.background='#ccc';
			for(var i=0;i<obj_li.length;i++){
				obj_li[i].style.display='none';
			}
			obj_li[num].style.display='block';
		}
	</script>
</body>
</html>

运行实例 »

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


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post