求JS大牛把下面的改成一个十天的倒计时,十天之后,这个DIV就消失<!DOCTYPE HTML>
<html>
<head>
<title> New Document </title>
<meta charset="gb2312">
<style>
#xs{margin:20px 0 0 0;color:#000;width:400px;margin:0 auto;font-weight:bolder;letter-spacing:5px}
#xs b{color:red;}
</style>
</head>
<body onload="nowTime()">
<script>
function nowTime(){
var td=new Date()
var h=23-td.getHours()
if (h<10)h="0"+h;
var m=59-td.getMinutes()
if (m<10)m="0"+m;
var s=60-td.getSeconds()
if (s<10)
{s="0"+s
}else if (s==60)
{
s="00"
}
document.getElementById('xs').innerHTML="<b>距明天还有:</b>"+h+"<b>小时</b>"+m+"<b>分</b>"+s+"<b>秒</b>"
t=setTimeout('nowTime()',50)
}
</script>
<div id='xs' >
</div>
</body>
</html>
<html>
<head>
<title> New Document </title>
<meta charset="gb2312">
<style>
#xs{margin:20px 0 0 0;color:#000;width:400px;margin:0 auto;font-weight:bolder;letter-spacing:5px}
#xs b{color:red;}
</style>
</head>
<body onload="nowTime()">
<script>
function nowTime(){
var td=new Date()
var h=23-td.getHours()
if (h<10)h="0"+h;
var m=59-td.getMinutes()
if (m<10)m="0"+m;
var s=60-td.getSeconds()
if (s<10)
{s="0"+s
}else if (s==60)
{
s="00"
}
document.getElementById('xs').innerHTML="<b>距明天还有:</b>"+h+"<b>小时</b>"+m+"<b>分</b>"+s+"<b>秒</b>"
t=setTimeout('nowTime()',50)
}
</script>
<div id='xs' >
</div>
</body>
</html>
解决方案 »
- SWFUPLOAD 保存文件问题
- 请帮忙看下,js 跨域 访问 window.opener问题
- 我想根据数据库里用户的生日计算出他的年龄(包含几岁几个月零几天)
- IE下Iframe的src属性设过几个后,scrollWidth获取问题
- 能用JavaScript协议来改百度搜索的背景颜色吗?
- 导航下拉菜单被下拉列表框覆盖了,怎么办?
- 鼠标移动到图片的某一个热点,显示一个popup窗口,怎么做
- 请教如何获得一个月的最后一天的日期(并非当前月份)
- 请教如何让浏览器的窗口不能被拖动?
- 求助!老师布置了一份提交表单的作业,我写完之后测试发现并不像预期的那样,但我不知道哪里错了,刚学javascript有好多地方不是很懂,求大佬帮帮忙!
- javascript运算
- jQuery 动画animate完成后回调
设置定时var target = new Date(2012, 06, 9, 00, 00, 00).getTime();06表示7月
<html>
<head>
<title>Javascript写的倒计时效果代码</title>
</head>
<body>
<script language="javascript" type="text/javascript">
var target = new Date(2012, 06, 9, 00, 00, 00).getTime();
function show_date_time(){
setTimeout("show_date_time()", 1000);
today=new Date();
timeold = target - today.getTime();
sectimeold=timeold/1000;
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000;
e_daysold=timeold/msPerDay;
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
if (daysold < 0) {
document.body.removeChild(document.getElementById("TimeCounter_0"));
return null;
}
else {
if (daysold<10) {daysold="0"+daysold}
if (hrsold<10) {hrsold="0"+hrsold}
if (minsold<10) {minsold="0"+minsold}
if (seconds<10) {seconds="0"+seconds}
if (daysold<3) {
document.getElementById("TimeCounter_0").innerHTML = "<font color=red>" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒</font>";
}
else {
document.getElementById("TimeCounter_0").innerHTML = daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
}
}
}
window.onload=show_date_time;
</script>
距10天后还有:
<div id="TimeCounter_0" style="border:1px solid black;margin:5px;padding:2px;width:140px"></div>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<title>New Document</title>
<meta charset="utf-8">
<style>
#xs {
margin:20px 0 0 0;
color:#000;
width:400px;
margin:0 auto;
font-weight:bolder;
letter-spacing:5px
}
#xs b {
color:red;
}
</style>
<script type="text/javascript">
var sEXP = '2012-07-09 23:59:59'; //设置到期时间
var oEXP = new Date(sEXP); //到期时间转换为Date对象
var t;
function countdown(oEXP) {
var now = new Date();
var xs = document.getElementById('xs');
if (now > oEXP) {
xs.parentNode.removeChild(xs); //到期移除div元素
window.clearInterval(t);
}
else {
var oTimeDiff = {};
var iTimeDiff = Math.round((oEXP.getTime() - now.getTime()) / 1000);
oTimeDiff.h = Math.floor(iTimeDiff / 3600), iTimeDiff -= oTimeDiff.h * 3600;
oTimeDiff.m = Math.floor(iTimeDiff / 60);
oTimeDiff.s = iTimeDiff - oTimeDiff.m * 60;
xs.innerHTML = '<b>距离' + sEXP + '还有:' + oTimeDiff.h + '小时' + oTimeDiff.m + '分' + oTimeDiff.s + '秒</b>';
}
}
window.onload = function() {
t = window.setInterval('countdown(oEXP)', 1000);
}
</script>
</head>
<body>
<div id='xs'></div>
</body>
</html>