當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。