利用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 ...
随机推荐
- 快速分析CPU性能问题
Linux的CPU性能问题,相信在工作中很容易遇到.这篇文章会总结出一个大概的套路,相信能够解决工作中90%以上的CPU性能问题! 会告诉大家在不同的场景下,cpu性能指标工具如何选择,性能瓶颈怎么找 ...
- MVVM 和 VUE三要素:响应式、模板引擎、渲染
MVVM 和 VUE三要素:响应式.模板引擎.渲染:https://blog.csdn.net/weixin_37644989/article/details/94409430
- codeforces 842C Ilya And The Tree (01背包+dfs)
(点击此处查看原题) 题目分析 题意:在一个树中,有n个结点,记为 1~n ,其中根结点编号为1,每个结点都有一个值val[i],问从根结点到各个结点的路径中所有结点的值的gcd(最大公约数)最大是多 ...
- 04: gitlab安装与使用
1.1 gitlab安装(192.168.56.12中安装) 1.GitLab是什么? 1. GitLab实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. 2. GitLa ...
- EM 算法(三)-GMM
高斯混合模型 混合模型,顾名思义就是几个概率分布密度混合在一起,而高斯混合模型是最常见的混合模型: GMM,全称 Gaussian Mixture Model,中文名高斯混合模型,也就是由多个高斯分布 ...
- redmine3.4.6安装教程
Redmine 是一个开源的.基于Web的项目管理和缺陷跟踪工具. 参考了网上各种文章,终于成功安装redmine-3.4.6. 1.下载安装railsinstaller-3.4.0.exe 官网下载 ...
- 从0开始入门ssm-crm系统实战
喜欢就点个赞呗! GitHub项目ssm-learn-crm show me the code and take to me,做的出来更要说的明白 1.1 克隆 git clone https://g ...
- VUE实现国际化
一.前言 趁着11月的最后一天,来写一篇关于前端国际化的实践型博客.国际化应该都不陌生,就是一个网站.应用可以实现语言的切换. 在这就不谈原理,只说说如何实现中英文的切换.做技术的总得先把 demo ...
- Python新式类与经典类(旧式类)的区别
看写poc的时候看到的,思考了半天,现在解决了 转载自http://blog.csdn.net/zimou5581/article/details/53053775 Python中类分两种:旧式类和新 ...
- Halide安装指南release版本
Halide安装指南 本版本针对Halide release版本 by jourluohua 使用的是Ubuntu 16.04 64位系统默认Gcc 4.6 由于halide中需要C++ 11中的特性 ...