当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


AngularJS ng-mouseleave用法及代码示例


当特定HTML元素上发生mouse-leave事件时,AngularJS中的ng-mouseleave指令用于应用自定义行为。当鼠标离开HTML元素中的特定位置时,可用于显示弹出警报。所有HTML元素都支持它。

用法:

 <element ng-mouseleave="expression"> content ... </element> 

范例1:


<!DOCTYPE html> 
<html> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/ 
    1.6.9/angular.min.js"></script> 
    <head> 
        <title>ng-mousedown Directive</title> 
    </head> 
    <body ng-app="" style="text-align:center"> 
        <h1 style="color:green">GeeksforGeeks</h1> 
        <h2>ng-mouseenter Directive</h2> 
        <div>price:</div> 
        <div ng-hide="leave" ng-mouseenter="leave=true"><span 
        class="amount">$ {{price}}</span></div> 
        <div ng-show="leave" ng-mouseleave="leave=false"> 
            <input type="number" class="form-control" 
            ng-model="price" ng-init="price=250" /> 
        </div> 
    </body> 
</html>

输出:
在Mouseleave之前:
ngmouseleave
在Mouseleave之后:
ngmouseleave

范例2:

<!DOCTYPE html> 
<html> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/ 
    1.6.9/angular.min.js"></script> 
    <head> 
        <title>ng-mouseleave Directive</title> 
       </head> 
     <body  ng-app="app" style="text-align:center"> 
        <h1 style="color:green">GeeksforGeeks</h1> 
        <h2>ng-mouseleave Directive</h2> 
  
        <div ng-controller="app"> 
            Input:<input type="text" ng-mouseleave="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>

输出:
在Mouseleave之前:
ngmouseleave
在Mouseleave之后:
ngmouseleave



相关用法


注:本文由纯净天空筛选整理自Vishal Chaudhary 2大神的英文原创作品 AngularJS | ng-mouseleave Directive。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。