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


AngularJS ng-dblclick用法及代碼示例


AngluarJS中的ng-dblclick指令用於將自定義行為應用於雙擊元素時。當它被單擊兩次時,它可以用於顯示或隱藏某些元素,或者可以彈出警報或更改文本的顏色。

用法:

<element ng-dblclick="expression"> Content... </element>

範例1:本示例使用ng-dblclick指令在雙擊按鈕後顯示警報消息。


<!DOCTYPE html> 
<html> 
      
<head> 
    <title>ng-dblclick Directive</title> 
  
    <script src= 
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> 
    </script> 
</head> 
   
<body ng-app="geek" style="text-align:center"> 
      
    <h1 style="color:green">GeeksforGeeks</h1> 
      
    <h2>ng-dblclick Directive</h2> 
      
    <div ng-controller="app"> 
        <button> 
            <a href="" ng-dblclick="alert()"> 
                Click Here 
            </a> 
        </button> 
    </div> 
      
    <script> 
        var app = angular.module("geek", []); 
        app.controller('app', ['$scope', function ($app) { 
            $app.alert = function () { 
                alert("This is an example of ng-dblclick"); 
            } 
        }]); 
    </script> 
</body> 
  
</html>

輸出:
雙擊之前:
ngdblclick
雙擊後:
ngdblclick

範例2:此示例在雙擊文本後更改了文本顏色。

<!DOCTYPE html> 
<html> 
      
<head> 
    <title>ng-dblclick Directive</title> 
  
    <script src= 
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> 
    </script> 
      
    <style type="text/css"> 
        .green { 
            color:green; 
        } 
    </style> 
</head> 
  
<body ng-app style="text-align:center"> 
      
    <h1 style="color:green">GeeksforGeeks</h1> 
      
    <h2>ng-click Directive</h2> 
      
    <div> 
        <p ng-dblclick="col=!col" ng-class="{green:col}"> 
            GeeksforGeeks is the computer science 
            portal for geeks. 
        </p> 
    </div> 
</body> 
  
</html>

輸出:
雙擊之前:
ngclick
雙擊後:
ngclick



相關用法


注:本文由純淨天空篩選整理自Vishal Chaudhary 2大神的英文原創作品 AngularJS | ng-dblclick Directive。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。