利用jquery 实现菜单控制对应视图的显示与隐藏
效果:



<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="./js/jquery-1.12.4.min.js" ></script>
<script type="text/javascript"> $(document).ready(function(){ $(".top div").click(function(){ //var arr = $(".top div"); switch ($(this).index()) { case 0:
console.log('0');
$(".top1").addClass("topSelect");
// 使用siblings获取被操作元素之外的同级元素,然后使用remove()删除
$(this).siblings().removeClass("topSelect"); $(".bottom1").removeClass("bottom-no-select").siblings().addClass('bottom-no-select'); break;
case 1:
console.log('1');
$(".top2").addClass("topSelect");
// 使用siblings获取被点击元素之外的同级元素,然后使用remove()删除
$(this).siblings().removeClass("topSelect");
$(".bottom2").removeClass("bottom-no-select").siblings().addClass('bottom-no-select'); break;
case 2:
console.log('2');
$(".top3").addClass("topSelect");
// 使用siblings获取被点击元素之外的同级元素,然后使用remove()删除
$(this).siblings().removeClass("topSelect");
$(".bottom3").removeClass("bottom-no-select").siblings().addClass('bottom-no-select'); break;
case 3:
console.log('3');
$(".top4").addClass("topSelect");
// 使用siblings获取被点击元素之外的同级元素,然后使用remove()删除
$(this).siblings().removeClass("topSelect");
$(".bottom4").removeClass("bottom-no-select").siblings().addClass('bottom-no-select'); break;
default: } });
}); // $(function(){
//
// }); </script>
<style media="screen">
.top{
background-color: yellow;
width: 100%;
height: 100px;
display: flex;
flex-direction: row;
}
.top1{
background-color: orange;
width: 100px;
height: 100%;
margin-left: 10px;
}
.top2{
background-color: orange;
width: 100px;
height: 100%;
margin-left: 10px;
}
.top3{
background-color: orange;
width: 100px;
height: 100%;
margin-left: 10px;
}
.top4{
background-color: orange;
width: 100px;
height: 100%;
margin-left: 10px;
} .bottom{
background-color: yellow;
width: 100%;
height: 200px;
display: flex;
flex-direction: row;
} .bottom1{
background-color: gray;
width: 100px;
height: 100%;
margin-left: 10px;
} .bottom11{
background-color: blue;
width: 100%;
height: 100%;
} .bottom2{
background-color: gray;
width: 100px;
height: 100%;
margin-left: 10px;
}
.bottom3{
background-color: gray;
width: 100px;
height: 100%;
margin-left: 10px;
}
.bottom4{
background-color: gray;
width: 100px;
height: 100%;
margin-left: 10px;
} .topSelect{
background-color: red;
} .bottom-no-select{
/* display:none; */
/* background-color: rgba(255,255,255,0); */
opacity: 0;
} </style>
</head>
<body> <div class="top">
<div class="top1 topSelect"> </div>
<div class="top2"> </div>
<div class="top3"> </div>
<div class="top4"> </div>
</div> <div class="bottom">
<div class="bottom1">
<div class="bottom11"> </div>
</div>
<div class="bottom2 bottom-no-select"> </div>
<div class="bottom3 bottom-no-select"> </div>
<div class="bottom4 bottom-no-select"> </div>
</div> </body> </html>
$(this).index() 表示同级中当前选取的元素的下标
$(".top1").addClass("topSelect"); 表示给某个标签添加一个类
$(this).siblings().removeClass("topSelect"); 使用siblings获取被操作元素之外的同级元素,然后使用remove()删除
$(function(){
// code fill
});
等价
jQuery(function(){
// code fill
});
等价
$(document).ready(function () {
// code fill
});
利用jquery 实现菜单控制对应视图的显示与隐藏的更多相关文章
- jQuery将物体居中,并且转换显示和隐藏
今天来给大家贴一段代码,代码的作用就是利用jQuery将物体居中,并且转换显示和隐藏: 首先建立一个div标签并且写好css样式,具体如下 然后我想要的效果是当我点击了button这个按钮,test可 ...
- 利用来JS控制页面控件显示和隐藏有两种方法
利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位. 方法一: 1 2 document.getEle ...
- JS控制HTML元素的显示和隐藏
JS控制HTML元素的显示和隐藏 利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位. 方法一: 1 2 ...
- 使用JavaScript控制HTML元素的显示和隐藏
利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位. 方法一: document.getElementB ...
- jquery怎么实现点击一个按钮控制一个div的显示和隐藏
示例html 1 2 <div class="abc" style="display:none"></div> <input ty ...
- 控制HTML元素的显示与隐藏——display和visibility
有些时候我们需要根据某些条件来控制Web页面中的HTML元素显示还是隐藏,可以通过display或visibility来实现.通过下面的例子了解display和visibility的区别,简单的例子代 ...
- iOS之 利用通知(NSNotificationCenter)获取键盘的高度,以及显示和隐藏键盘时修改界面的注意事项
我们在开发中会遇到这样的情况:调用键盘时需要界面有一个调整,避免键盘遮掩输入框. 但实现时你会发现,在不同的手机上键盘的高度是不同的.这里列举一下: //获取键盘的高度 /* iphone 6: 中文 ...
- jquery总结06-动画事件01-基础显示和隐藏
动画事件 .hide(option) 动画隐藏 会保存元素的原始属性值 $("#a2").hide({ duration: 3000, complete: function() ...
- jquery 点击按钮实现listbox的显示与隐藏,点击其他地方按钮外的地方,隐藏listbox
本来不知道如何获取服务器的控件的,这下知道可以这么做了,所以记录下来.... <asp:ImageButton ID="alltime" ImageUrl="ima ...
随机推荐
- nginx - 反向代理 - 配置文件模板 - nginx 代理tcp的服务 - 部署示意图
danjan01deiMac:~ danjan01$ cat /usr/local/etc/nginx/nginx.conf|grep -v '^$' worker_processes 1; even ...
- 论文阅读 | Trojaning Attack on Neural Networks
对神经网络的木马攻击 Q: 1. 模型蒸馏可以做防御吗? 2. 强化学习可以帮助生成木马触发器吗? 3. 怎么挑选建立强连接的units? 本文提出了一种针对神经元网络的木马攻击.模型不直观,不易被人 ...
- Emgu 学习(3) 绘图,使用鼠标绘图,使用trackbar
绘图 class Program { static void Main(String[] args) { Mat img = , , DepthType.Cv8U, ); img.SetTo(, , ...
- json字段为null时输出空字符串
Map < String , Object > jsonMap = new HashMap< String , Object>(); jsonMap.put(); jsonMa ...
- WIN32_FIND_DATA
基本信息 编辑 关于文件的全部属性信息.总计有以下以下9种:文件的标题名.文件的属性(只读.存档,隐藏等).文件的创建时间.文件的最后访问时间.文件的最后修改时间.文件大小的高位双字.文件大小的低位双 ...
- 上课笔记:awk
awk [单独的编程语言解释器]1.awk介绍 全称:Aho Weinberger Kernaighan 三个人的首字母缩写: 1970年第一次出现在Unix机器上,后来在开源领域使用它: 所以,我 ...
- zip 命令
NAME zip - package and compress (archive) files SYNOPSIS zip [-aABcdDeEfFghjklLmoqrRSTuvVwXy ...
- SQL语句规范
SQLStructure Query Language,结构化查询语言 1.规范(1)mysql对于SQL语句不区分大小写,SQL语句关键字尽量大写 show databases;show DataB ...
- python简单验证码识别
在学习python通过接口自动登录网站时,用户名密码.cookies.headers都好解决但是在碰到验证码这个时就有点棘手了:于是通过网上看贴,看官网完成了对简单验证码的识别,如果是复杂的请看大神的 ...
- Selenium在IE浏览器中执行脚本时输入字符太慢问题解决方法
问题描述: IE浏览器中执行Selenium脚本的时候发现输入文本的时候总是一个字符一个字符的输入,并且输入每个字符之间都隔几秒. 解决方案: 将使用的IE浏览器驱动由64位的换成32位的.