返回js控制div...登陆

js控制div

ifhover2019-05-06 10:14:25213
<!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进行更改样式

最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送