用JS实现状态栏显示时间时,为什么不可以直接调用showtime()函数,而要再写一个stopclock()函数呢?

用JS实现状态栏显示时间时,为什么不可以直接调用showtime()函数,而要再写一个stopclock()函数呢?,第1张

什么意思啊??

function stopClock() 停止页面计时;

function startClock() 开始页面计时;

function showTime() 在顶级窗口的状态栏中显示停留时间;

功能不一样啊。

一般的处理方式是在前台通过JS控制,JS控制显示时间的代码如下,各种不同的显示方式:

[javascript]

function Clock() {

var date = new Date()

this.year = date.getFullYear()

this.month = date.getMonth() + 1

this.date = date.getDate()

this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()]

this.hour = date.getHours() <10 ? "0" + date.getHours() : date.getHours()

this.minute = date.getMinutes() <10 ? "0" + date.getMinutes() : date.getMinutes()

this.second = date.getSeconds() <10 ? "0" + date.getSeconds() : date.getSeconds()

this.toString = function() {

return "现在是:" + this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day

}//现在是<span id="clock">现在是:2013年3月6日 13:54:17 星期三</span>

[javascript]

<span></span>

this.toSimpleDate = function() {

return this.year + "-" + this.month + "-" + this.date

}//2013-03-06

this.toDetailDate = function() {

return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second

}//2013-03-06 13:45:43

this.display = function(ele) {

var clock = new Clock()

ele.innerHTML = clock.toString()//显示方式调用

window.setTimeout(function() {clock.display(ele)}, 1000)

}

}

<html>

<head>

<title></title>

<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>

<script type="text/javascript">

function clickButton(obj){

var obj = $(obj)

obj.attr("disabled","disabled")

var time = 60

var set=setInterval(function(){

obj.val(--time)

}, 1000)

setTimeout(function(){

obj.attr("disabled",false).val("获取验证码")

clearInterval(set)

}, 60000)

}

</script>

</head>

<body class="newbody">

<input type="button" value="获取验证码" onclick="clickButton(this)"/>

</body>

</html>

自己写个button样式吧。。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11927123.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存