
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独自运行是动态增加的,我要按钮点击后动态增加该怎么改? 展开
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独自运行是动态增加的,我要按钮点击后动态增加该怎么改? 展开
1个回答
展开全部
<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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询