zoukankan      html  css  js  c++  java
  • angularjs实现时钟效果

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>动态时间例子</title>
    <script src="js/angular.min.js"></script>
    <script>
    var app=angular.module("timeDemo",[]);
    app.controller("timeCtrl",function($scope){
    //获取当前时间
    var now1=new Date();
    //让时间在页面显示
    $scope.Now=now1.getHours()+':'+now1.getMinutes()+':'+now1.getSeconds();

    //写一个方法获取当前时间
    $scope.SetTimer=function(){
    //angularJs的特性,需要手动把变化映射到html元素上面
    $scope.$apply(function(){
    var now=new Date();
    $scope.Now=now.getHours()+':'+now.getMinutes()+':'+now.getSeconds();
    });
    };
    //每隔1秒刷新一次时间
    $scope.SetTimerInterval=setInterval($scope.SetTimer,1000);
    });
    </script>
    </head>
    <body ng-app="timeDemo" ng-controller="timeCtrl">
    当前时间为:{{Now}}
    </body>
    </html>

  • 相关阅读:
    博客园转文章的方法
    http协议相关面试题
    接口测试基础01
    文件上传下载
    括号-回溯
    幂集-回溯
    分割数组为连续子序列- -贪心法
    不使用临时变量交换数字
    计数质数
    拼接最大值
  • 原文地址:https://www.cnblogs.com/luoguixin/p/6166334.html
Copyright © 2011-2022 走看看