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


AngularJS ng-mouseup用法及代码示例


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>

输出:
离开元素后:
ngmouseup
单击元素后:
ngmouseup

范例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>

输出:
在单击元素之前:
ngmousedown
单击元素后:
ngmousedown



相关用法


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