博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js练习【DOM操作】
阅读量:6909 次
发布时间:2019-06-27

本文共 3532 字,大约阅读时间需要 11 分钟。

完成效果:

演示地址:

 

 

HTML:

	
[js小练习]:DOM操作
选择颜色
绿
定制尺寸

  

 

 

 

界面呈现:

*{		padding: 0;		margin:0;	}	body{		font-family: "microsoft yahei";	}   #testField{   	width: 120px;   	height: 120px;   	background-color: #333;   	position: absolute;   	top: 0;   	right: 0;   	bottom: 0;   	left: 0;   	margin:auto;   }   .coverBg{ /*遮罩层*/   	display: none;   	position: fixed;   	width: 100%;   	height: 100%;   	background-color: rgba(0,0,0,.4);   }   .selBox{    width: 200px;    height: 300px;    padding:10px;    font-size: 13px;    border-radius:3px;    background-color: rgba(255,255,255,.4);    position: absolute;    top: 0;    right: -350px;    bottom: 0;    left: 0;    margin:auto;    box-shadow: 0 0 6px rgba(0,0,0,.3);   }   dl{   	display: inline-block;   }   dl dt{   	font-size: 13px;   	font-weight: bold;   	margin: 5px 0;   	padding-bottom: 5px;   	border-bottom: 1px solid #f7f7f7;   }   .commonEle{           display:inline-block;      width: 50px;   	height: 50px;   	border-radius: 25px;   	text-align: center;   	line-height: 50px;   	color:#fff;   	float: left;   	margin:5px 8px;   }   #red{   	background-color: red;   }   #green{   	background-color: green;   }   #blue{   	background-color: blue;   }   .comEle {  margin: 10px;}.comEle input {  margin: 5px 0;  width: 100%;  height: 24px;  border: 1px solid #999;  border-radius: 3px;  box-shadow: inset 0 0 3px rgba(0,0,0,.3);}.btn-list dd{	float: left;}.btnEle {  padding: 5px 25px;  border: 0;  outline: 0;  box-shadow: 0 1px 2px rgba(0,0,0,.075);  border-radius: 2px;  margin: 5px 11px;  color: #666;}.btn-save{  background-image: -webkit-gradient(linear, left top, left bottom, from(#e3262e), to(#ab171e));  background-image: -webkit-linear-gradient(#e3262e, #ab171e);  background-image: linear-gradient(#e3262e, #ab171e);  text-shadow: 0 -1px rgba(0, 0, 0, 0.11);  color: #fff;}

 

JS部分:

var oField=document.getElementById('testField');var oCover=document.getElementById('coverBox');var oRed=document.getElementById('red');var oGreen=document.getElementById('green');var oBlue=document.getElementById('blue');var olength=document.getElementById('olength');var owidth=document.getElementById('owidth');var oOffBtn=document.getElementById('offBtn');var oSaveBtn=document.getElementById('saveBtn');olength.οninput=function(){var h_value=olength.value +"px";oField.style.height=h_value;	}owidth.οninput=function(){var w_value=owidth.value +"px";oField.style.width=w_value;	}oField.οnclick=function(){oCover.style.display="block";}oRed.οnclick=function(){	oField.style.backgroundColor="red";}oGreen.οnclick=function(){	oField.style.backgroundColor="green";}oBlue.οnclick=function(){	oField.style.backgroundColor="blue";}oOffBtn.οnclick=function(){	oCover.style.display="none";	oField.style.height="120px";	oField.style.width="120px";	oField.style.backgroundColor="#333";	//取消的时候清空input数值        olength.value='';        owidth.value='';}oSaveBtn.οnclick=function(){	oCover.style.display="none";	//保存的时候清空input数值	olength.value='';        owidth.value='';}

  

转载于:https://www.cnblogs.com/kevinCoder/p/4482281.html

你可能感兴趣的文章
C#常见问题总结(二)
查看>>
Linux系统基础-Linux系统文件操作常用命令
查看>>
网络工程师成长日记307-XX公安监控中心技术支持回忆录
查看>>
JavaWeb17-HTML篇笔记(二)
查看>>
vlan虚拟局域网
查看>>
简练软考知识点整理-估算成本过程
查看>>
Cobbler自动装机,Cobbler Web管理的两种认证方式登录
查看>>
部署社交网站(SVN+PHP+NGINX+MYSQL+MFS)
查看>>
PXE 网络装机——实现无人值守批量装机
查看>>
【爱项目、爱管理】项目成本管理如何做到又好又省钱
查看>>
云计算入门学习资料,linux云计算学习大纲
查看>>
大数据开发语言学习指南:新人快速学习大数据的套路
查看>>
好用的企业邮箱有哪些?
查看>>
Oracle热备份
查看>>
动态规划之经典例题
查看>>
gitlab web hooks 应用
查看>>
STM32的停机模式与唤醒
查看>>
安全运维之端口安全
查看>>
十月百度,阿里巴巴,迅雷搜狗最新面试七十题(更新至10.17)
查看>>
java程序c:forEach相关实际应用
查看>>