簡體   English   中英

如何以角度更改onmouseout的innerHTML內容

[英]How to change the innerHTML content onmouseout in angular

我必須使用Angular在mouseenter上將按鈕的內容更改為ON,在mouseleave上將按鈕的內容更改為OFF。

<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>  
$scope.alert = function () {  
    $scope.text = 'OFF';
};  
$scope.text = function () {  
    $scope.text = 'ON';  
};

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

為什么不使用綁定呢?

<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>  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM