<!DOCTYPE html> <html> <head> <Meta charset="utf-8"> <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script> </head> <body> <div ng-app="myApp" ng-controller="myCtrl"> <h1 id="myh1">{{hello}}</h1> </div> <script> var app = angular.module('myApp',[]); app.controller('myCtrl',function($scope,$interval) { $scope.hello = "Hello world!"; var flag = 0; $interval(function () { if (flag===0){ $scope.hello = "I love you"; document.getElementById("myh1").style.color="red"; flag = 1; } else { $scope.hello = "Hello world!"; document.getElementById("myh1").style.color="blue"; flag = 0; } },1000); }); </script> </body> </html>
效果:
+++++++++++++++++++
原文链接:https://www.f2er.com/angularjs/148576.html