感觉前端没有任何问题,所以不想写作业,但是或许是因为学了JQuey的缘故,js真的是写起来,到处都错,还有个问题,jquery文档就虚函数不是可以省略一部分吗,js window.onlad=function(){}y也有省略写法把
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>js控制元素</title>
<style>
#box{width: 250px; height: 250px; background:pink;}
</style>
<script>
var box
window.onload=function(){
box=document.getElementById('box');
}
function a(){
box.style.height='500px';
}
function b(){
box.style.width='500px';
}
function c(){
box.style.background='#ff6500';
}
function d(){
box.style.height='250px';
box.style.width='250px';
box.style.color='pink';
}
function e(){
box.style.display='none';
}
function f(){
box.style.display='block';
}
</script>
</head>
<body>
<div id="box"></div>
<input type="button" value="变高" onclick="a()" >
<input type="button" value="变宽" onclick="b()">
<input type="button" value="变色" onclick="c()">
<input type="button" value="重置" onclick="d()">
<input type="button" value="隐藏" onclick="e()" >
<input type="button" value="显示" onclick="f()">
</body>
</html>