总结:
function 函数名称(参数){
var声明一个变量=document.getElementById()在文档中找括号中的id
var声明一个变量=a.document.getElementByTabName()在变量a中找a标签
for(i=0;i<a_a.length;//i小于变量a_a的长度;i++){
a_a[i].style.display="none"//把变量a_a里面的a隐藏
}
a_a[参数].style.display=“block”"//把变量a_a里面的a显示
}
实例
<!DOCTYPE html> <html> <head> <title>123</title> <meta charset="utf-8"> <link rel="icon" type="image/x-icon" href="static/images/favicon.ico"> <style type="text/css"> div{height: 300px;width: 500px;position: relative;margin:50px auto;overflow: hidden;} img{height: 300px;width: 500px; } p{display:inline-block;width: 500px;height: 30px;position: absolute;bottom:0;color: #fff;text-align: center;margin: 20px auto;} p span{display:inline-block;width: 20px;height: 20px;border:20px;background: rgba(254,254,254,0.6);border-radius: 50%;line-height: 20px;text-align:center;cursor:pointer;} </style> </head> <body> <div id="banner"> <a href=""><img src="static/images/1.jpg"></a> <a href=""><img src="static/images/2.jpg"></a> <a href=""><img src="static/images/3.jpg"></a> <a href=""><img src="static/images/4.jpg"></a> <a href=""><img src="static/images/5.jpg"></a> <p> <span onclick="ban(0)">1</span> <span onclick="ban(1)">2</span> <span onclick="ban(2)">3</span> <span onclick="ban(3)">4</span> <span onclick="ban(4)">5</span> </p> <script type="text/javascript"> function ban(ner){ var a=document.getElementById('banner'); var a_a=a.getElementsByTagName('a'); for(var i=0;i<a_a.length;i++){ a_a[i].style.display="none"; } a_a[ner].style.display="block" } </script> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例