AngularJS中的ng-mouseup指令用于在特定HTML元素上发生mouseup事件时应用自定义行为。当按下鼠标按钮时,它可用于显示弹出警报。所有HTML元素都支持它。
用法:
<element ng-mouseup="expression"> Contents... </element>
范例1:本示例使用ng-mouseup指令更改文本效果。
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
<title>ng-mouseup Directive</title>
</head>
<body ng-app style="text-align:center">
<h1 style="color:green">GeeksforGeeks</h1>
<h2>ng-mouseup Directive</h2>
<div>
<p ng-mouseup="geek={'color':'green',
'font-size':'larger'}"
ng-mousedown="geek={'font-size':''}"
ng-style="geek" ng-class="'button'">
Hold mouse click to see effect.
</p>
</div>
</body>
</html>
输出:
离开元素后:
单击元素后:
范例2:本示例使用ng-mouseup指令显示数组元素。
<!DOCTYPE html>
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
<title>ng-mouseup Directive</title>
</head>
<body ng-app="app" style="padding:20px">
<h1 style="color:green">GeeksforGeeks</h1>
<h2>ng-mouseup Directive</h2>
<div ng-controller="app">
<div ng-repeat="p in array">
<div style="background-color:green;color:white;
height:30px;width:10%" ng-mouseup="mouseOver(p)">
{{p}}
</div><br>
</div>
<pre>You just clicked:<b>{{input}}</b></pre>
</div>
<script>
var app = angular.module("app", []);
app.controller('app', ['$scope', function ($scope)
{
$scope.mouseOver = function (data) {
$scope.input = data;
};
$scope.array = ["First", "Second"]
}]);
</script>
</body>
</html>
输出:
在单击元素之前:
单击元素后:
相关用法
- AngularJS ng-if用法及代码示例
- AngularJS ng-cut用法及代码示例
- AngularJS ng-value用法及代码示例
- AngularJS ng-src用法及代码示例
- AngularJS ng-app用法及代码示例
- AngularJS ng-csp用法及代码示例
- AngularJS ng-jq用法及代码示例
- AngularJS ng-required用法及代码示例
- AngularJS ng-bind用法及代码示例
- AngularJS ng-srcset用法及代码示例
- AngularJS ng-paste用法及代码示例
- AngularJS ng-submit用法及代码示例
- AngularJS ng-style用法及代码示例
- AngularJS ng-selected用法及代码示例
注:本文由纯净天空筛选整理自Vishal Chaudhary 2大神的英文原创作品 AngularJS | ng-mouseup Directive。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。