一. 重点: CSS 样式, js 的 dom 取值, js 的事件
JQuey 引入地址
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script> https://cdn.bootcss.com/jquery/2.2.4/jquery.js ;
二. js 原生代码
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta charset="UTF-8">
- <title > 实践题 - 选项卡 </title>
- <style type="text/css">
- / CSS 样式制作 /*{margin:0;padding:0;font:normal 12px "微软雅黑";color:#000000;}
- #tabs{width:290px; height:150px; padding:5px; margin:20px;}
- #tabs ul{list-style:none; display:block; height:30px; line-height:30px;}
- #tabs ul li{
- float:left; width:60px; height:28px; line-height:28px; text-align:center;
- display:inline-block;margin:0px 3px; border:1px solid #aaa;border-bottom:none;
- cursor:pointer; background:#fff; list-style:none;
- }
- #tabs ul li.on{border-top:2px solid saddlebrown; border-bottom:2px solid #fff;}
- #tabs div{
- height:120px; line-height:25px; border:1px solid #336699;border-top:2px saddlebrown solid;padding:5px;}
- .hide{display:none;}
- </style>
- <script type="text/javascript" src="jquery-1.10.2.min.js">
- // JS 实现选项卡切换
- window.onload = function() {
- var oTab = document.getElementById("tabs");
- var oUl = oTab.getElementsByTagName("ul")[0];
- var oLis = oUl.getElementsByTagName("li");
- var oDivs = oTab.getElementsByTagName("div");
- for(var i=0;i<oLis.length;i++) {
- oLis[i].index = i;
- // var text = oLis[i].getAttribute("index");
- // document.write(text+"<br>");
- // console.log(oLis[i].innerHTML);
- oLis[i].onclick = function() {
- for(var n=0;n<oLis.length;n++) {
- oLis[n].className = "";
- oDivs[n].className = "hide";
- }
- this.className = "on";
- oDivs[this.index].className = "";
- }
- }
- }
- </head>
- <body>
××× 家具二手房 ** 三. jQuery 写法 **
来源: http://www.bubuko.com/infodetail-2667653.html