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"> </span>
<span onclick= "blue()" style="background-color: blue"> </span>
<span onclick= "yellow()" style="background-color: yellow"> </span>
<span onclick= "gray()" style="background-color: gray"> </span>
<span onclick= "green()" style="background-color: green"> </span>
</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>