onclick怎样调用动态js函数?

在html页面中引用了js函数,这个函数是动态显示计时的:代码如下:varbegintime=newDate(localStorage.getItem("btime"))... 在html页面中引用了 js函数,这个函数是动态显示计时的:代码如下:
var begintime=new Date(localStorage.getItem("btime"));
function ourtimes(){
var nowtime = new Date();
var t=parseInt((nowtime.getTime()-begintime.getTime())/1000);
d=parseInt(t/3600/24);
h=parseInt((t/3600)%24);
m=parseInt((t/60)%60);
s=parseInt(t%60);
document.getElementById("times").innerHTML="已经开始了:"+d+"天 "+h+"时"+m+"分"+s+"秒";
}
ourtimes()
var sh;
sh=setInterval(ourtimes,1000);
然后在html按钮里调用它onclick=“ourtimes();",运行结果是时间计时是不会动态增加的,而js独自运行是动态增加的,我要按钮点击后动态增加该怎么改?
展开
 我来答
莫路草根
2015-04-13 · TA获得超过4102个赞
知道大有可为答主
回答量:4184
采纳率:85%
帮助的人:1028万
展开全部
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="times"></div>
<br/>
<input type="button" value="Click" id="click" onclick="ourtimes();" />
</body>
<script>
function ourtimes(){
setInterval(autototime,1000);
}
function autototime()
{
var begintime=new Date(localStorage.getItem("btime"));
var nowtime = new Date();
var t=parseInt((nowtime.getTime()-begintime.getTime())/1000); 
d=parseInt(t/3600/24); 
h=parseInt((t/3600)%24); 
m=parseInt((t/60)%60); 
s=parseInt(t%60); 
document.getElementById("times").innerHTML="已经开始了:"+d+"天 "+h+"时"+m+"分"+s+"秒"; 
}
</script>
</html>
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式