• HTML计时事件(JavaScript)网页电子钟+网页计时器


     setTimeout("函数","未来指定毫秒后调用函数");

    clearTimeout(setTimeout("函数","未来指定毫秒后调用函数"));

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>title>
    6. head>
    7. <body>
    8. <button onclick="starTime()">开始button>
    9. <button onclick="stopTime()">停止button>
    10. <script>
    11. var t;
    12. function fun() {
    13. alert("Hello World");
    14. }
    15. function starTime() {
    16. t=setTimeout("fun()",300);
    17. }
    18. function stopTime()
    19. {
    20. clearTimeout(t);
    21. alert(t);
    22. }
    23. script>
    24. body>
    25. html>

     setInterval("fun()",3000);每隔指定时间调用

    clearInterval(t);取消setIntval()

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>title>
    6. head>
    7. <body>
    8. <button onclick="starTime()">开始button>
    9. <button onclick="stopTime()">停止button>
    10. <script>
    11. var t;
    12. function fun() {
    13. alert("Hello World");
    14. }
    15. function starTime() {
    16. t=setInterval("fun()",3000);
    17. }
    18. function stopTime()
    19. {
    20. clearInterval(t);
    21. alert(t);
    22. }
    23. script>
    24. body>
    25. html>

    计时器

    三个功能  开始 复位 停止 

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>title>
    6. <style>
    7. div {
    8. height: 50px;
    9. width: 100px;
    10. background-color: skyblue;
    11. padding: auto;
    12. text-align: center;
    13. line-height: 50px;
    14. border: 2px solid black;
    15. position: relative;
    16. cursor: pointer;
    17. border-radius: 5px;
    18. font-weight: 200px;
    19. font-size: 20px;
    20. }
    21. .start {
    22. top: 100px;
    23. right: -500px;
    24. }
    25. .stop {
    26. top: 45px;
    27. right: -700px;
    28. }
    29. .zero {
    30. top: -100px;
    31. right: -600px;
    32. }
    33. .time {
    34. height: 100px;
    35. width: 300px;
    36. top: 50px;
    37. right: -500px;
    38. font-size: 80px;
    39. text-align: center;
    40. line-height: 100px;
    41. font-family: "宋体";
    42. font-weight: 1000;
    43. }
    44. div:hover {
    45. background-color: darkgray;
    46. }
    47. style>
    48. head>
    49. <body>
    50. <div class="start" onclick="start()">开始div>
    51. <div class="stop" onclick="stop()">停止div>
    52. <div class="zero" onclick="reset()">复位div>
    53. <div class="time" id="time">0div>
    54. <script>
    55. var s = 0;
    56. var t;
    57. function start() //开始计时
    58. {
    59. if (!t)
    60. t = setInterval("change()", 1000);
    61. }
    62. function reset() //复位
    63. {
    64. clearInterval(t);
    65. s = -1;
    66. change();
    67. t = null;
    68. }
    69. function stop() // 停止计时
    70. {
    71. clearInterval(t);
    72. t = null;
    73. }
    74. function change() {
    75. s++;
    76. var x = document.getElementById("time");
    77. x.innerHTML = s;
    78. }
    79. script>
    80. body>
    81. html>

    电子钟:每秒更新一次页面 

    1. html>
    2. <html>
    3. <head>
    4. <meta charset="utf-8">
    5. <title>电子表title>
    6. <style>
    7. .table {
    8. height: 100px;
    9. width: 500px;
    10. background-color: grey;
    11. text-align: center;
    12. margin: auto;
    13. border-radius: 5px;
    14. border: 4px solid black;
    15. font-size: 20px;
    16. }
    17. style>
    18. <script>
    19. function updateTime() {
    20. var date = new Date();
    21. document.getElementById("year").innerText = date.getFullYear();
    22. document.getElementById("month").innerText = date.getMonth() + 1;
    23. document.getElementById("day").innerText = date.getDate();
    24. document.getElementById("hour").innerText = date.getHours();
    25. document.getElementById("minutes").innerText = date.getMinutes();
    26. document.getElementById("second").innerText = date.getSeconds();
    27. }
    28. setInterval(updateTime, 1000);
    29. script>
    30. head>
    31. <body onload="updateTime()">
    32. <table class="table">
    33. <th id="year">th>
    34. <th>th>
    35. <th id="month">th>
    36. <th>th>
    37. <th id="day">th>
    38. <th>th>
    39. <th id="hour">th>
    40. <th>:th>
    41. <th id="minutes">th>
    42. <th>:th>
    43. <th id="second">th>
    44. table>
    45. body>
    46. html>

     

     

  • 相关阅读:
    mybatis-plus通用业务分页查询封装
    黑马旅游网-JavaWeb学成练手小项目-包含老师资料
    html在线阅读小说网页制作模板 小说书籍网页设计 大学生静态HTML网页源码 dreamweaver网页作业 简单网页课程成品
    记忆化搜索 day48
    算法为屠龙刀,设计模式为倚天剑
    OpenCV-基于阴影勾勒的图纸清晰度增强算法
    Sality 病毒的驱动模块分析报告
    207.课程表
    Unity做360度全景预览
    SQL注入之宽字节注入
  • 原文地址:https://blog.csdn.net/m0_71385141/article/details/133281093