js 制作秒表效果
来源:互联网 发布:什么是字符串数组 编辑:程序博客网 时间:2024/05/22 00:53
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.time {
width: 200px;
height: 100px;
background-color: #ccc;
text-align: center;
line-height: 50px;
font-size: 30px;
border-radius: 50px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="time">
<span id="sid"></span>
</br>
<button id="stop">停止</button>
<button id="start">开始</button>
</div>
</body>
<script type="text/javascript">
function getDate() {
var mytime = new Date();
/*year = mytime.getFullYear();
month = mytime.getMonth();
day = mytime.getDate();*/
/*hour = mytime.getHours();*/
hour = mytime.getHours();
if(hour < 10) {
hour = "0" + hour;
}
minutes = mytime.getMinutes();
if(minutes < 10) {
minutes = "0" + minutes;
}
secound = mytime.getSeconds();
if(secound < 10) {
secound = "0" + secound;
}
var str = hour + ":" + minutes + ":" + secound;
sidobj = document.getElementById("sid");
sidobj.innerHTML = str;
}
getDate(); // 因为没有内容,所以先执行一边代码获取当前的值 ,然后再继续1秒一个刷新
stopObj = setInterval(getDate, 1000);
/*setInterval(function(){
getDate();
},1000);*/
function stop() {
clearInterval(stopObj);
}
bobj = document.getElementById("stop");
bobj.onclick = function() {
stop();
}
function start() {
stopObj = setInterval(getDate, 0);
}
startObj = document.getElementById("start");
startObj.onclick = function() {
start();
}
</script>
</html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
.time {
width: 200px;
height: 100px;
background-color: #ccc;
text-align: center;
line-height: 50px;
font-size: 30px;
border-radius: 50px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="time">
<span id="sid"></span>
</br>
<button id="stop">停止</button>
<button id="start">开始</button>
</div>
</body>
<script type="text/javascript">
function getDate() {
var mytime = new Date();
/*year = mytime.getFullYear();
month = mytime.getMonth();
day = mytime.getDate();*/
/*hour = mytime.getHours();*/
hour = mytime.getHours();
if(hour < 10) {
hour = "0" + hour;
}
minutes = mytime.getMinutes();
if(minutes < 10) {
minutes = "0" + minutes;
}
secound = mytime.getSeconds();
if(secound < 10) {
secound = "0" + secound;
}
var str = hour + ":" + minutes + ":" + secound;
sidobj = document.getElementById("sid");
sidobj.innerHTML = str;
}
getDate(); // 因为没有内容,所以先执行一边代码获取当前的值 ,然后再继续1秒一个刷新
stopObj = setInterval(getDate, 1000);
/*setInterval(function(){
getDate();
},1000);*/
function stop() {
clearInterval(stopObj);
}
bobj = document.getElementById("stop");
bobj.onclick = function() {
stop();
}
function start() {
stopObj = setInterval(getDate, 0);
}
startObj = document.getElementById("start");
startObj.onclick = function() {
start();
}
</script>
</html>
阅读全文
0 0
- js 制作秒表效果
- 原生js代码实现秒表效果
- 秒表制作
- 制作秒表
- js 秒表
- CSS3制作秒表
- CSS3制作秒表
- js秒表程序
- JS秒表倒计时器
- js秒表计时器
- JS简易秒表计时器
- JS简易秒表计时器
- 秒表js开始结束
- Pocket PC简单制作秒表
- 利用VB制作一个秒表
- js制作淘宝放大镜效果
- js定时循环实现秒表
- 用JS制作tab选项卡效果
- Eclipse和Intellij idea切换
- 关于Mat
- resource busy and acquire with nowait..
- Android:关于onActivityResult方法不执行的问题
- Verilog RTL 代码设计——译码器&计数器
- js 制作秒表效果
- kmean法和dbscan法的直观比较
- 生产者和消费者问题-使用BlockingQueue来实现
- linux的定时任务crontab详解
- 【python 生成自己的二维码】推广二维码带log图片
- 动态规划总结
- Java读取配置文件(Properties类)
- py必备基础知识
- 总结分析 v4l2 捕捉图片 (三)