2015-11-05 43 views
0

我必須使用Angular將mouseenter上的按鈕內容更改爲ON,並將鼠標離開時的按鈕內容更改爲OFF。如何更改角度上的innerHTML內容onmouseout

<html ng-app="myApp" ng-controller="homeCtrl"> 
<head> 
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> 
<script> 
var app = angular.module('myApp', []); 
app.controller('homeCtrl', function ($scope) { 
$scope.alert = function() { 
    this.myHTML = OFF; 
}; 
$scope.text = function() { 
    this.myHTML = ON; 
}; 
}) 
</script> 
</head> 
<body> 
<button ng-mouseenter="alert();" ng-mouseleave="text();"> OFF </button> 
</body> 
</html> 
+0

您是否在「this」上測試了innerHTML屬性? –

回答

0
$scope.alert = function() { 
    $scope.text = 'OFF'; 
}; 
$scope.text = function() { 
    $scope.text = 'ON'; 
}; 

<button ng-mouseenter="alert();" ng-mouseleave="text();">{{text}}</button> 
0

爲什麼不使用綁定呢?

<html ng-app="myApp" ng-controller="homeCtrl"> 
<head> 
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> 
<script> 
var app = angular.module('myApp', []); 
app.controller('homeCtrl', function ($scope) { 
$scope.alert = function() { 
    $scope.value = "OFF"; 
}; 
$scope.text = function() { 
    $scope.value = "ON"; 
}; 

$scope.value="OFF" 
}) 
</script> 
</head> 
<body> 
<button ng-mouseenter="alert();" ng-mouseleave="text();"> {{value}} </button> 



</body> 
</html>