javascript程序设计这题怎么写?求大神指点
2个回答
展开全部
<html>
<head>
</head>
<body>
<span id="time_span"> </span><button type="button" flag="1" id="btn" onclick="pauseOrStart(this)"></button>
<script>
var timeSpan=document.getElementById('time_span');
var btn=document.getElementById('btn');
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 5, //月份
"d+": this.getDate(), //日
"H+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)){
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));//RegExp.$1是yyyy,将yyyy替换为当前年份,并根据4-yyyy的长度开始截取
}
for (var k in o){
if (new RegExp("(" + k + ")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));//如果是10月,即使是一个M同样会展示10;
}
}
return fmt;
}
var getTime=function(){return new Date().Format("yyyy-MM-dd HH:mm:ss");};
timeSpan.innerHTML=getTime();
btn.innerHTML="暂停";
var startInterval=setInterval(function(){timeSpan.innerHTML=getTime();},1000);
var startTime=function(){startInterval=setInterval(function(){timeSpan.innerHTML=getTime();},1000);};
var pauseTime=function(){clearInterval(startInterval);};
function pauseOrStart(o){
var flag=o.getAttribute("flag");
if(flag=="1"){
pauseTime();o.setAttribute("flag","0");o.innerHTML="开始";
}else{
startTime();o.setAttribute("flag","1");o.innerHTML="暂停";
}
}
</script>
</body>
</html>
<head>
</head>
<body>
<span id="time_span"> </span><button type="button" flag="1" id="btn" onclick="pauseOrStart(this)"></button>
<script>
var timeSpan=document.getElementById('time_span');
var btn=document.getElementById('btn');
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 5, //月份
"d+": this.getDate(), //日
"H+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)){
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));//RegExp.$1是yyyy,将yyyy替换为当前年份,并根据4-yyyy的长度开始截取
}
for (var k in o){
if (new RegExp("(" + k + ")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));//如果是10月,即使是一个M同样会展示10;
}
}
return fmt;
}
var getTime=function(){return new Date().Format("yyyy-MM-dd HH:mm:ss");};
timeSpan.innerHTML=getTime();
btn.innerHTML="暂停";
var startInterval=setInterval(function(){timeSpan.innerHTML=getTime();},1000);
var startTime=function(){startInterval=setInterval(function(){timeSpan.innerHTML=getTime();},1000);};
var pauseTime=function(){clearInterval(startInterval);};
function pauseOrStart(o){
var flag=o.getAttribute("flag");
if(flag=="1"){
pauseTime();o.setAttribute("flag","0");o.innerHTML="开始";
}else{
startTime();o.setAttribute("flag","1");o.innerHTML="暂停";
}
}
</script>
</body>
</html>
展开全部
<!DOCTYPE html>
<script type="text/javascript">
function addZero(n){
if(n<10){
return '0'+n;
}else{
return ''+n;
}
};
function trick(){
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDay();
var H = addZero(date.getHours());
var M = addZero(date.getMinutes());
var S = addZero(date.getSeconds());
var t = year+"-"+month+"-"+day+" "+H +":"+ M +":"+S;
document.getElementById('timearea').innerHTML = t;
}
var clock = null;
window.onload = function(){ start();}
function stop(){
clearInterval(clock);
}
function start(){
clock = setInterval(trick,1000);
}
</script>
<body>
<div id='timearea'></div>
<button onclick="stop();">stop</button>
<button onclick="start();">start</button>
</body>
</html>
<script type="text/javascript">
function addZero(n){
if(n<10){
return '0'+n;
}else{
return ''+n;
}
};
function trick(){
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDay();
var H = addZero(date.getHours());
var M = addZero(date.getMinutes());
var S = addZero(date.getSeconds());
var t = year+"-"+month+"-"+day+" "+H +":"+ M +":"+S;
document.getElementById('timearea').innerHTML = t;
}
var clock = null;
window.onload = function(){ start();}
function stop(){
clearInterval(clock);
}
function start(){
clock = setInterval(trick,1000);
}
</script>
<body>
<div id='timearea'></div>
<button onclick="stop();">stop</button>
<button onclick="start();">start</button>
</body>
</html>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询