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