您的位置:首页 > Web前端 > JavaScript

js实现灯泡的开和灭

2016-02-23 13:07 627 查看
<html>

<head>

<meta http-equiv="content-type" content="text/html;charset=utf-8"/>

<style type="text/css">

.div_1{width:160px;height:216px;background-image:url(bulb_off.png);}

.div_2{width:160px;height:216px;background-image:url(bulb_on.png);}

</style>

<script language="javascript">

function openlamp(){

var div = document.getElementById("lamp");

div.className ="div_2";

}

function closelamp(){

var div = document.getElementById("lamp");

div.className ="div_1";

}

</script>

</head>

<body>

<div class="div_2" id="lamp">

</div>

<input type="button" value="开" onclick="openlamp()"/>

<input type="button" value="关" onclick="closelamp()"/>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: