AngularJS – ng-mousedown 指令

AngularJS 中的ng-mousedown 指令基本上指定了鼠标按下事件的自定义事件。每当按下鼠标并调用 mouse-down 事件时,我们都可以执行多个功能。

语法

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

示例 - ngMousedown 指令

在您的 Angular 项目目录中创建一个文件“ ngMousedown.html ”并复制粘贴以下代码片段。

<!DOCTYPE html>
<html>
   <head>
      <title>ngMousedown Directive</title>

      <script xx_src="https://cdn.staticfile.org/angularjs/1.6.9/angular.min.js"></script>
   </head>

   <body ng-app style="text-align: center;">
      <h1 style="color: green;">
         Welcome to nhooo.com
      </h1>
      <h2>
         angularjs | ngMousedown Directive
      </h2>

      <div>
         <p
            ng-mousedown="demo={'background-color':'green','font-size':'larger'}"
            ng-mouseup="demo={'font-size':''}"
            ng-style="demo"
            ng-class="'button'"
         >
            Click mouse and hold !!!
         </p>
      </div>
   </body>
</html>
输出结果

要运行上述代码,只需转到您的文件并将其作为普通 HTML 文件运行即可。