//开/关
var only = document.getElementById('only');
var centerBox = document.getElementById('centerBox');
var off_2=document.getElementById("off_2");
//获取实际宽高
// var centerW=centerBox.offsetWidth;
// var centerH=centerBox.offsetHeight;
// var off=document.getElementById('off'); //颜色
var red = document.getElementById("red");
var blue = document.getElementById("blue");
var yellow=document.getElementById("yellow"); //Width
var w100=document.getElementById("w100");
var w200=document.getElementById("w200");
var w300=document.getElementById("w300"); //Height
var h100=document.getElementById("h100");
var h200=document.getElementById("h200");
var h300=document.getElementById("h300"); //BorderSize
var b1=document.getElementById("b1");
var b2=document.getElementById("b2");
var b3=document.getElementById("b3"); //Border-color
var fs=document.getElementById("fs");
var green=document.getElementById("green");
var cs=document.getElementById("cs"); //重置
var reset=document.getElementById("reset"); //方法一:通过if...else....语句判断方法
// function show() {
// if (centerBox.style.display == 'none') {
// centerBox.style.display = 'block';
// }else {
// centerBox.style.display='none';
// }
//
// }; // 方法三:通过缩写判断方法;
// function show() {
// centerBox.style.display = (centerBox.style.display=="none"?"block":"none");
// }; //方法四:匿名函数
only.onclick=function(){
// off.style.display = (off.style.display=="none"?"block":"none");
// centerBox.style.display = (off.style.display=="none"?"block":"none");
off.style.display='block';
centerBox.style.display = 'block';
//垂直居中-自动获取宽高
//重置
var reset=document.getElementById("reset");
reset.onclick=function(){
sl.removeAttribute("style");
console.log(centerBox.removeAttribute("style"));
}; }; off.onclick=function(){
// centerBox.style.display = (off.style.display=="none"?"block":"none");
// off.style.display = (off.style.display=="none"?"block":"none");
centerBox.style.display='none';
off.style.display='none';
}; off_2.onclick=function(){
// centerBox.style.display = (off.style.display=="none"?"block":"none");
// off.style.display = (off.style.display=="none"?"block":"none");
centerBox.style.display='none';
off.style.display='none';
}; //Background-color
red.onclick=function () {
sl.style.background='red';
}; blue.onclick=function(){
sl.style.background='blue';
}; yellow.onclick=function(){
sl.style.background='yellow';
}; //Width
w100.onclick=function(){
sl.style.width='100'+'px';
};
w200.onclick=function(){
sl.style.width='200'+'px';
};
w300.onclick=function(){
sl.style.width='300'+'px';
}; //Height
h100.onclick=function(){
sl.style.height='100'+'px';
};
h200.onclick=function(){
sl.style.height='200'+'px';
};
h300.onclick=function(){
sl.style.height='300'+'px'
}; //BorderSize
b1.onclick=function(){
sl.style.borderWidth='1'+'px';
};
b2.onclick=function(){
sl.style.borderWidth='5'+'px'
};
b3.onclick=function(){
sl.style.borderWidth='10'+'px';
}; //Border-color
fs.onclick=function(){
sl.style.borderColor='#f7c2dc';
};
green.onclick=function(){
sl.style.borderColor='green';
};
cs.onclick=function(){
sl.style.borderColor='#fb7703';
}; // centerBox.style.marginLeft='-'+centerW+'px';
//
// centerBox.style.marginTop='-'+centerH+'px';
#only{
width: 150px;
height: 50px;
line-height: 50px;
text-align: center;
border-radius: 10px;
background: red;
margin: 5px 0;
color: #fff;
font-weight: bold;
cursor: pointer;
} #sl{
width: 147px;
height: 147px;
border: 3px solid #3c3c3c;
background: #0a1015;
} #off{
position: absolute;
top:;
left:;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
} #centerBox{
position: absolute;
top: 50%;
left: 50%;
width: 272px;
height: 317px;
margin-top: -158.5px;
margin-left: -136px;
border: 2px solid #0a1015;
background: yellow;
padding: 8px;
box-sizing: border-box;
} .Tit{
width: 60px;
height: 35px;
line-height: 35px;
display: inline-block;
margin: 5px 0;
text-align: center;
font-weight: bold;
} .cl{
width: 50px;
height: 33px;
line-height: 33px;
display: inline-block;
border: 2px solid #3c3c3c;
text-align: center;
margin: 5px 5px;
cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="DOMSTYLE.css"> <title>Title</title>
</head>
<body>
<div id="only">点击进入选项</div>
<div id="sl"></div>
<div id="off" style="display: none;"></div>
<div id="centerBox" style="display: none">
<div><span class="Tit">颜色:</span><span id="red" class="cl">红色</span><span id="blue" class="cl">蓝色</span><span id="yellow" class="cl">黄色</span></div>
<div><span class="Tit">宽度:</span><span id="w100" class="cl">100</span><span id="w200" class="cl">200</span><span id="w300" class="cl">300</span></div>
<div><span class="Tit">高度:</span><span id="h100" class="cl">100</span><span id="h200" class="cl">200</span><span id="h300" class="cl">300</span></div>
<div><span class="Tit">边框:</span><span id="b1" class="cl">1</span><span id="b2" class="cl">3</span><span id="b3" class="cl">6</span></div>
<div><span class="Tit">框色:</span><span id="fs" class="cl">粉色</span><span id="green" class="cl">绿色</span><span id="cs" class="cl">橙色</span></div>
<div><span class="Tit"></span><span id="reset" class="cl">重置</span> <span id="off_2" class="cl">关闭</span></div>
</div>
<script src="DOME06.js"></script>
</body>
</html>

JavaScript-点击任意点显示隐藏的更多相关文章

  1. js点击 密码输入框密码显示隐藏

    很多密码框都有个眼睛标记,点击能显示密码.原理就是点击切换password为text等显示 下面上代码 <!DOCTYPE html> <html> <head> ...

  2. angular学习笔记(八)-控制视图显示隐藏

    本篇介绍angular控制视图的显示和隐藏: 通过给元素添加ng-show属性或者ng-hide属性来控制视图的显示或隐藏: ng-show: 绑定的数据值为true时,显示元素,值为false时,隐 ...

  3. javascript 点击按钮实现隐藏显示切换效果

    原文链接:http://www.jb51.net/article/79083.htm <html> <head> <meta charset="gb2312&q ...

  4. python 全栈开发,Day50(Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏)

    一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...

  5. 前端JavaScript(1) --Javascript简介,第一个JavaScript代码,数据类型,运算符,数据类型转换,流程控制,百度换肤,显示隐藏

    一.Javascript简介 Web前端有三层: HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) Jav ...

  6. 点击自动显示/隐藏DIV代码。(简单实用)

    注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 很多时候我们需要将DIV的信息默认为隐藏状态,只有当用户点击时才显示DIV中包含的提示文字.这类效果在互联网上应用得很多,但实现的方 ...

  7. HTML5--》点击显示隐藏内容

    <details>浏览器支持比较差,可以用JavaScript实现这种功能. <!doctype html> <html> <head> <met ...

  8. 点击按钮显示隐藏DIV,点击DIV外面隐藏DIV

    点击按钮显示隐藏DIV,点击DIV外面隐藏DIV 注意:此方法对touch事件不行,因为stopPropagation并不能阻止touchend的冒泡 <style type="tex ...

  9. javascript进行百度换肤 和显示隐藏一个窗口的操作

    简单的运用javascript来进行百度换肤的操作 <!DOCTYPE html> <html lang="en"> <head> <me ...

随机推荐

  1. OAF实现下拉菜单联动

    当需要输入多个下拉菜单选项时,可能某些下拉菜单是有级联关系的.这时候就需要使用级联的下拉菜单来解决.下面的教程将介绍如何使用ppr制作级联下拉菜单 一.新建AM 在test.oracle.apps.c ...

  2. 学习C++模板,类模板

    当我们使用向量时,会经常使用形如:vector<int> a的式子.这个表达式就是一个类模板实例化的例子,vector是一个类模板,我们给他传递模板参数(见<>里),然后创建一 ...

  3. LeetCode之“动态规划”:Dungeon Game

    题目链接 题目要求: The demons had captured the princess (P) and imprisoned her in the bottom-right corner of ...

  4. “《编程珠玑》(第2版)第2章”:C题(查找变位词,排序)

    C题是这样子的: 给定一个英语字典,找出其中的所有变位词集合.例如,“pots”.“stop”和“tops”互为变位词,因为每一个单词都可以通过改变其他单词中字母的顺序来得到. 下段分析摘自该书(P1 ...

  5. Access text files using SQL statements by DB Query Analyzer

    Access text files using SQL statements by DB Query Analyzer Ma Gen feng (Guangdong Unitoll Services ...

  6. LeetCode(51)- Count and Say

    题目: The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 11 ...

  7. IT轮子系列(六)——Excel上传与解析,一套代码解决所有Excel业务上传,你Get到了吗

    前言 在日常开发当中,excel的上传与解析是很常见的.根据业务不同,解析的数据模型也都不一样.不同的数据模型也就需要不同的校验逻辑,这往往需要写多套的代码进行字段的检验,如必填项,数据格式.为了避免 ...

  8. java小知识点汇总

    1.ConcurrentHashMap使用segment来分段和管理锁,segment继承自ReentrantLock,因此ConcurrentHashMap使用ReentrantLock来保证线程安 ...

  9. java程序的内存分配(一)

      首 页 阅览室 馆友 我的图书馆 帐号 java程序的内存分配(一) 收藏  JAVA 文件编译执行与虚拟机(JVM)介绍  Java 虚拟机(JVM)是可运行Java代码的假想计算机.只要根据J ...

  10. JDK 常用命令

    一) 引言:    当我们安装完JDK时,除了必须的编译运行以外,它就已经自带了很多辅助工具.正所谓“工欲善其事,必先利其器.”如果能用好这些工具,它们将大大方便你的开发.它们的实用和方便有时甚至会使 ...