AngularJS中的ng-mouseover指令用于在特定HTML元素上发生鼠标悬停事件时应用自定义行为。当鼠标移到特定元素上时,它可用于显示弹出警报。所有HTML元素都支持它。
用法:
<element ng-mouseover="expression"> Contents... </element>
范例1:当鼠标移到元素上时,此示例使用ng-mouseover指令显示内容。
<!DOCTYPE html>
<html>
<head>
<title>ng-mouseover Directive</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
<style type="text/css">
.geek {
border:1px solid black;
width:400px;
background-color:green;
border-radius:4px;
height:20px;
color:white;
}
</style>
</head>
<body ng-app="">
<center>
<h1 style="color:green">
GeeksforGeeks
</h1>
<h2>ng-mouseover Directive</h2>
<div ng-init="geek=false">
<button ng-mouseover="geek=true"
ng-mouseleave="geek=false">
Mouse over me!
</button>
<br><br>
<div class="geek" ng-show="geek">
GeeksforGeeks is the computer
science portal for geeks.
</div>
</div>
</center>
</body>
</html>
输出:
将鼠标悬停在元素上之前:
将鼠标悬停在元素上之后:
范例2:本示例使用ng-mouseover指令在鼠标移到元素上时显示警报消息。
<!DOCTYPE html>
<html>
<head>
<title>ng-mouseover Directive</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>
<body ng-app="app" style="text-align:center">
<h1 style="color:green">GeeksforGeeks</h1>
<h2>ng-mouseover Directive</h2>
<div ng-controller="app">
Input:<input type="text" ng-mouseover="alert()"
ng-model="click" />
</div>
<script>
var app = angular.module("app", []);
app.controller('app', ['$scope', function ($scope) {
$scope.click = 'geeksforgeeks';
$scope.alert = function () {
alert($scope.click);
}
}]);
</script>
</body>
</html>
输出:
将鼠标悬停在元素上之前:
将鼠标悬停在元素上之后:
相关用法
- AngularJS ng-if用法及代码示例
- AngularJS ng-cut用法及代码示例
- AngularJS ng-value用法及代码示例
- AngularJS ng-src用法及代码示例
- AngularJS ng-app用法及代码示例
- 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-mouseover Directive。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。