利用js简单实现页面

1.实现如下效果

在这里插入图片描述

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>1-7</title>
	</head>
	<style>
		#box{
			width: 400px;
			height: 400px;
		}
	</style>
	<script type = "text/javascript">
			var box = document.getElementById("box");
			function red(){
				document.getElementById("box").style.background = "red";
			}
			function blue(){
				document.getElementById("box").style.background = "blue";
			}
			function yellow(){
				document.getElementById("box").style.background = "yellow";
			}
			function gray(){
				document.getElementById("box").style.background = "gray";
			}
			function green(){
				document.getElementById("box").style.background = "green";
			}
			function small(){
				document.getElementById("box").style.fontSize = "12px";
			}
			function middle(){
				document.getElementById("box").style.fontSize = "24px";
			}
			function big(){
				document.getElementById("box").style.fontSize = "48px";
			}
			function change(){
				var width = parseInt(document.getElementById("width").value);
				var height = parseInt(document.getElementById("height").value);
				document.getElementById("box").style.width = width + "px";
				document.getElementById("box").style.height = height + "px";
			}
			function hide(){
				document.getElementById("bt").value = (document.getElementById("bt").value == '隐藏')?'显示':'隐藏';
				document.getElementById("box").style.display = (document.getElementById("box").style.display == 'none')?'block':'none';
			}
		
		</script>
	<body>
		<p>单击改变背景颜色:
			<span onclick= "red()" style = "background-color: red">&nbsp;&nbsp;&nbsp;</span>&nbsp;
			<span onclick= "blue()" style="background-color: blue">&nbsp;&nbsp;&nbsp;</span>&nbsp;
			<span onclick= "yellow()" style="background-color: yellow">&nbsp;&nbsp;&nbsp;</span>&nbsp;
			<span onclick= "gray()" style="background-color: gray">&nbsp;&nbsp;&nbsp;</span>&nbsp;
			<span onclick= "green()" style="background-color: green">&nbsp;&nbsp;&nbsp;</span>&nbsp;
			</p>
		<p>单击改变字体大小:
			<span onclick="small()">小</span>
			<span onclick="middle()">中</span>
			<span onclick="big()">大</span>
		</p>
		<p>
			高:<input type = "text" id = "height">
			宽:<input type = "text" id = "width">
			<input type = "button" onclick="change()" value = "改变窗口大小">
		</p>
		<p><input type = "button" id = "bt" onclick="hide()" value = "隐藏"></p>
		<div id = "box">
		<p>计算机工程学院</p>
		</div>
	</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值