<!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>
<script type="text/javascript">
var i=10;
function show(){
var div=document.createElement('div');
div.style.cssText='position:absolute;top:0px;bottom:0px;left:0px;right:0px;filter:alpha(opacity=50);opacity:0.5;background-color:black;';
document.body.appendChild(div);
var span=document.createElement('span');
span.style.cssText='position:absolute;left:50%;top:50%;';
span.innerHTML=i--;
document.body.appendChild(span);
return span;
}
window.onload=function(){
document.getElementById('test').onclick=function(){
var span=show();
var p=window.setInterval(function(){
if(i>0){
span.innerHTML=i--;
}else{
window.clearInterval(p);
window.location.href='http://www.baidu.com';
}
},1000);
}
}
</script>
</head><body>
<input type="button" value="show" id="test">
</body>
</html>类似这样试试
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var i=10;
function show(){
var div=document.createElement('div');
div.style.cssText='position:absolute;top:0px;bottom:0px;left:0px;right:0px;filter:alpha(opacity=50);opacity:0.5;background-color:black;';
document.body.appendChild(div);
var span=document.createElement('span');
span.style.cssText='position:absolute;left:50%;top:50%;';
span.innerHTML=i--;
document.body.appendChild(span);
return span;
}
window.onload=function(){
document.getElementById('test').onclick=function(){
var span=show();
var p=window.setInterval(function(){
if(i>0){
span.innerHTML=i--;
}else{
window.clearInterval(p);
window.location.href='http://www.baidu.com';
}
},1000);
}
}
</script>
</head><body>
<input type="button" value="show" id="test">
</body>
</html>类似这样试试
解决方案 »
- 把当前时间转换成指定时区的时间时,运行结果不对,求高手解答!
- 如何在超链接中同时实现锚记和调用函数?
- 帮助修改我的代码:如何通过单击页面图像使两幅图像交替出现
- 怎样用javascript删除用户选定的表格行?
- FCKeditor编辑器中怎么用JAVASCRIPT取得当前编辑器中的值??
- 哪位可以提供个IE、FF通用的颜色选择器,不胜感激200分
- 大家知道这样的文件如何下载吗,up有分~多谢啦~ ---答案
- 帮我看看这个语句是什么意思啊
- 一个可能是javascript的问题?
- 各位老大帮帮忙,帮我看看吧,很着急的,我都折腾好久了,网上也找不到相关资料~~~~~:((
- 求大神帮让以下代码兼容IE6/IE7
- jsp中的a标签
//这个function主要是为了定义对应的元素,就不详细解释了,有问题继续留言哦
function show()
{
var div=document.createElement('div');
div.style.cssText='position:absolute;top:0px;bottom:0px;left:0px;right:0px;filter:alpha(opacity=50);opacity:0.5;background-color:black;';
document.body.appendChild(div);
var span=document.createElement('span');
span.style.cssText='position:absolute;left:50%;top:50%;';
span.innerHTML=i--;
document.body.appendChild(span);
return span;
}
//当整个页面加载完毕后,会自动执行function这个方法
window.onload=function(){
//为页面元素id为test的元素的onclick属性添加对应的方法
document.getElementById('test').onclick=function(){
//调用上面的show这个function
var span=show();
//下面这个是设置了一个定时器,这个定时器的作用是每隔1000毫秒都会调用一次下面的这个function
var p=window.setInterval(function()
{
if(i>0)
{
span.innerHTML=i--;
}else
{
//清除掉定时器
window.clearInterval(p);
//跳转到对应的页面
window.location.href='http://www.baidu.com';
}
},1000);
}
}
</script>
如果还是不明白的话,建议去学习一下js的基础知识,比如定时器啦,比如window这个对象,