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


AngularJS ng-mouseenter用法及代码示例


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

用法:

 <element ng-mouseenter="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-mouseenter Directive</title> 
        </head> 
    <style type="text/css"> 
        .outerDiv { 
            width:100px; 
            height:100px; 
            background-color:green; 
            margin-left:40px; 
        } 
    </style> 
    <body ng-app style="padding:30px"> 
            <h1 style="color:green">GeeksforGeeks</h1> 
            <h2>ng-mouseenter Directive</h2> 
            <div class="outerDiv" ng-mouseenter="oc=oc+1;outer=true" 
                ng-mouseleave="outer=false"> 
                <p style="text-align:center;color:white">Mouse  
                     {{outer==true?'Enter':'Out'}}</p> 
                <br /> 
  
                <p style="text-align:center;color:white"> 
               {{oc}}<br /></p> 
            </div> 
    </body> 
</html>

输出:
在Mouseenter之前:
ngmousedown
在Mouseenter之后:
ngmousedown

范例2:

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

输出:
在Mouseenter之前:
ngmousedown
在Mouseenter之后:
ngmousedown



相关用法


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