点击挂上事件,点击移除事件+进度条例题

 

无标题文档

点击挂上事件 点击移除事件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<style type="text/css">
*{ margin:0px auto; padding:0px; font-family:微软雅黑; font-size:14px;}

</style>

</head>
<body>
<div id="dd" style="width:200px; height:200px; background-color:#669">
这是一个层
</div>
<span onclick="add1()">点击挂上事件</span>
<span onclick="remove1()">点击移除事件</span>

</body>
<script type="text/javascript">
function showdd()
{
alert("被点中了");
}
function add1()
{
var d = document.getElementById("dd");
d.onclick = function (){showdd()}; //匿名函数
}
function remove1()
{
var d = document.getElementById("dd");
d.onclick = function (){}; //空匿名函数
}

</script>
</html>
2.进度条

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
*{ margin:0px auto; padding:0px}
#wai{ width:200px; height:10px; border:1px solid #60F;}
#nei{ width:0px; height:10px; background-color:#F33; float:left}
</style>
</head>

<body>

<div style="width:600px; height:300px; margin-top:30px">


<div id="wai">
<div id="nei">

</div>
</div>

<input type="button" value="开始" onclick="Start()" />
</div>

</body>
<script type="text/javascript">

function Start()
{
Bian();
}

var bfb = 0;
function Bian()
{
//将百分比变化
bfb= bfb+1;

//改变宽度
document.getElementById("nei").style.width = bfb+"%";

//判断
if(bfb<100)
{
window.setTimeout("Bian()",50);
}

}

</script>
</html>

posted on 2016-09-27 11:59  向前看!明天会更好!  阅读(122)  评论(0编辑  收藏  举报