js改变div属性

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			body{
				margin: 0px;
				padding: 0px;
			}
			#show
			{
				background: red;
				width: 100px;
				height: 50px;
				float: left;
				margin-top: 15px;
				margin-left: 10px;
				color: white;
				display: block;
				float: left;
				
			}
			h1
			{
				float: left;
			}
			#link
			{
				width: 200px;
				height: 200px;
				border: 5px solid black;
				background: gainsboro;
				float: left;
				position:absolute;
				top: 100px;
				left: 100px;
			}
			#bg
			{
				position: absolute;
				display:none;
				left:0;
				top:0;
				z-index:10;
				background:#DCDBDC;
				-moz-opacity: 0.8;
				opacity:.80;
				filter: alpha(opacity=80);
				
			}
			#sz
			{
				position: absolute;
				display:none;
				width:500px;
				height:300px;
				left:50%;
				top:40%;
				z-index:11;
				background:#B8F764; 
			}
			#sz ul
			{
				margin: 0px;
				padding: 0px;
				width: 240px;
				height: 220px;
				float: left;
				
			}
			#sz ul li
			{
				line-height: 30px;
				text-align: center;
				width: 240px;
				height: 80px;
				list-style:none;
				
			}
		
			#sz div div
			{
				margin-left: 20px;
				line-height: 30px;
				text-align: center;
				width: 50px;
				height: 40px;
				float: left;
			}
			#sz a
			{
				float: left;
				text-decoration: none;
			}
		</style>
	</head>
	<body>
		<h1>请为下面的div设置样式:</h1>
		<button id="show" οnclick="show()">点击设置</button>
		<div id="link"></div>
		<div id="bg" > </div>
		<div id="sz" >
			<div>
				<ul>
					<li>请选择背景颜色:
						
					</li>
					<li>请选择宽度(px):
						
					</li>
					<li>请选择高度(px):
						
					</li>
				</ul>
				<ul style="float: right;">
					<li>
						<div id="red" style="background: green;">红色</div>
						<div id="yellow" style="background: deepskyblue;">黄色</div>
						<div id="blue" style="background: pink;">蓝色</div>
					</li>
					<li>
						<div id="w200" style="background: whitesmoke;">200</div>
						<div id="w300" style="background: whitesmoke;">300</div>
						<div id="w400" style="background: whitesmoke;">400</div>
					</li>
					<li>
						<div id="h200" style="background: whitesmoke;">200</div>
						<div id="h300" style="background: whitesmoke;">300</div>
						<div id="h400" style="background: whitesmoke;">400</div>
					</li>
				</ul>
			</div>
			<div><a href="#" οnclick="returns()">恢复</a><a href="javascript:void(0)" οnclick="closeBox()">关闭</a></div>
			
		</div>
		<script>
			
			var link=document.getElementById("link");
			function closeBox()
			{
				bg.style.display="none";
				sz.style.display="none";
			}
			function show()
			{
				var bg=document.getElementById("bg");
				var sz=document.getElementById("sz");
				
				bg.style.width=document.body.scrollWidth + "px";
				bg.style.height=document.body.scrollHeight+"px";
				
				bg.style.display="block";
				sz.style.display="block";
			}
			
			function returns()
			{
				link.style.width="200px";
				link.style.height="200px";
				link.style.background="gainsboro";
			}
			var red=document.getElementById("red");
			var yellow=document.getElementById("yellow");
			var blue=document.getElementById("blue");
			
			var w200=document.getElementById("w200");
			var w300=document.getElementById("w300");
			var w400=document.getElementById("w400");
			
			var h200=document.getElementById("h200");
			var h300=document.getElementById("h300");
			var h400=document.getElementById("h400");
			
			red.οnmοuseοver=function()
			{
				link.style.background="red";
				red.style.background="red";
			}
			
			yellow.οnmοuseοver=function()
			{
				link.style.background="yellow";
				yellow.style.background="yellow";
			}
			
			blue.οnmοuseοver=function()
			{
				link.style.background="blue";
				blue.style.background="blue";
			}
			
			w200.οnmοuseοver=function()
			{
				link.style.width="200px";
				w200.style.background="bisque";
			}
			w300.οnmοuseοver=function()
			{
				link.style.width="300px";
				w300.style.background="bisque";
			}
			w400.οnmοuseοver=function()
			{
				link.style.width="400px";
				w400.style.background="bisque";
			}
			h200.οnmοuseοver=function()
			{
				link.style.height="200px";
				h200.style.background="bisque";
			}
			h300.οnmοuseοver=function()
			{
				link.style.height="300px";
				h300.style.background="bisque";
			}
			h400.οnmοuseοver=function()
			{
				link.style.height="400px";
				h400.style.background="bisque";
			}
			
			
			
		</script>
	</body>
</html>

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值