css,javascript,JQuey制作页面切换

发布时间:2020-08-01 10:01:26 作者:一百个小排
来源:网络 阅读:503

php练习-javascript,JQuey制作页面切换

一.重点:css样式,js的dom取值,js的事件

JQuey引入地址
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>

二.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>
<!-- HTML页面布局 -->
<div id="tabs">
<ul>
<li class="on">×××</li><li>家具</li><li>二手房</li>
</ul>
<div>
购昌平邻铁三居 总价20万买一居<br>
内购五环三居 140万安家东三环<br>
北京首现零首付楼盘 53万购东5环50平<br>
京楼盘直降5000 中信府 公园楼王现房<br>
</div>
<div class="hide">
出租屋大改造 美少女的混搭小窝<br>
经典清新简欧爱家 90平老房焕发新生<br>
新中式的酷色温情 66平撞色活泼家居<br>
瓷砖就像选好老婆 卫生间烟道的设计<br>
</div>
<div class="hide">
通州豪华3居260万 二环稀缺2居250w甩<br>
西3环通透2居290万 130万2居限量抢购<br>
黄城根小学学区仅260万 121平70万抛!<br>
独家别墅280万 苏州桥2居优惠价248万<br>
</div>
</body>
</html>

三.jQuery写法
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>实践题 - 选项卡</title>
<style type="text/css">
/ CSS样式制作 /
{margin:0;padding:0;font:normal 13px "微软雅黑";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;
margin:0px 3px; border:1px solid #aaa; border-bottom:2px;
cursor:pointer; background:#fff; list-style:none;
}
tabs ul li.on{border-top: 2px solid saddlebrown; border-bottom: 0 solid #fff; border-left: 2px solid saddlebrown; border-right: 2px solid saddlebrown;}
tabs div{
height:120px; line-height:25px; border:1px solid #336699;border: 2px solid saddlebrown; padding:5px;display: none;}
tabs div.on {display: block;}
</style>

<script type="text/javascript" src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
<script type="text/javascript">

// JQuery实现选项卡切换
$(document).ready(function() {
$("ul li").click(function () {
var index = $(this).index();
$(this).addClass("on").siblings().removeClass("on");
$("#tabs div").hide().eq(index).show();
});
});

</script>

</head>
<body>
<!-- HTML页面布局 -->
<div id="tabs">
<ul>
<li class="on">×××</li>
<li>家具</li>
<li>二手房</li>
</ul>
<div class='on'>
购昌平邻铁三居 总价20万买一居<br>
内购五环三居 140万安家东三环<br>
北京首现零首付楼盘 53万购东5环50平<br>
京楼盘直降5000 中信府 公园楼王现房<br>
</div>
<div>
出租屋大改造 美少女的混搭小窝<br>
经典清新简欧爱家 90平老房焕发新生<br>
新中式的酷色温情 66平撞色活泼家居<br>
瓷砖就像选好老婆 卫生间烟道的设计<br>
</div>
<div>
通州豪华3居260万 二环稀缺2居250w甩<br>
西3环通透2居290万 130万2居限量抢购<br>
黄城根小学学区仅260万 121平70万抛!<br>
独家别墅280万 苏州桥2居优惠价248万<br>
</div>
</body>
</html>

四.页面输出
相比之下,jQuery的写法比较简洁

css,javascript,JQuey制作页面切换

推荐阅读:
  1. 安装Aptana以及安装jquey 支持的过程
  2. jquey写的简单图片轮转

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

切换卡 js jquery

上一篇:mongodb中in和all有什么不同

下一篇:解决mongodb发生错误100的问题

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》