js控制div

Original 2019-05-06 10:14:25 215
abstract:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,
<!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>Document</title>
<style>
#box{
width:150px;
height:150px;
background-color:red;
}
</style>
</head>
<body>
<div id="box">
</div>
<input type="button" onclick="color()" value="变色">
<input type="button" onclick="w()" value="变宽">
<input type="button" onclick="h()" value="变高">
<input type="button" onclick="block()" value="显示">
<input type="button" onclick="none()" value="隐藏">
<script>
var box = document.getElementById('box');
function color(){
box.style.backgroundColor="blue";
}
function w(){
box.style.width="300px";
}
function h(){
box.style.height="300px";
}
function block(){
box.style.display="block";
}
function none(){
box.style.display="none";
}
</script>
</body>
</html>

通过getElementByID来获取要操作的div,然后通过style进行更改样式

Correcting teacher:查无此人Correction time:2019-05-07 09:30:24
Teacher's summary:完成的不错。js语言很强大,要多练习。继续加油

Release Notes

Popular Entries