【Angularjs文档翻译及实例】DOM事宜

把Angularjs当中触及DOM事宜的属性整顿一下,此文档是基于1.4.8英文文档整顿的。

商定:
此文中ngXxx示意ng-xxx属性名。

ngBlur

用法

<window, input, select, textarea, a
  ng-blur="expression">
...
</window, input, select, textarea, a>

参数

参数范例概况
ngBlurexpression表达式将在落空核心时被触发(事宜对象与$event一样可取得)

ngFocus

用法

<window, input, select, textarea, a
  ng-focus="expression">
...
</window, input, select, textarea, a>

参数

参数范例概况
ngFocusexpression表达在取得核心时被触发(事宜对象与$event一样可取得)

ngChange

用法

<input
  ng-change="expression">
...
</input>

参数

参数范例概况
ngChangeexpression表达式将在input控件被转变时触发

ngChecked

用法

<INPUT
  ng-checked="expression">
...
</INPUT>

参数

参数范例概况
ngCheckedexpression假如表达式为真,那末就会在元素上设置checked属性

ngClick

用法

<ANY
  ng-click="expression">
...
</ANY>

参数

参数范例概况
ngClickexpression当被点击的时刻触发表达式(事宜对象与$event一样可取得)

ngKeydown/ngKeypress/ngKeyup

用法

<ANY
  ng-keydown="expression">
...
</ANY>
<ANY
  ng-keypress="expression">
...
</ANY>
<ANY
  ng-keyup="expression">
...
</ANY>

参数

参数范例概况
ngKeydownexpression表达式在按键按下时被触发(事宜对象与$event一样可取得,而且能够查询keyCode, altKey等)
ngKeypressexpression表达式在按键按下时被触发(事宜对象与$event一样可取得,而且能够查询keyCode, altKey等)
ngKeyupexpression表达式在按键开释时被触发(事宜对象与$event一样可取得,而且能够查询keyCode, altKey等)

ngMousedown/ngMouseup

用法

<ANY
  ng-mousedown="expression">
...
</ANY>
<ANY
  ng-mouseup="expression">
...
</ANY>

参数

参数范例概况
ngMousedownexpression表达式在鼠标按下时被触发(事宜对象与$event一样可取得)
ngMouseupexpression表达式在鼠标开释时被触发(事宜对象与$event一样可取得)

ngMouseenter/ngMousemove

用法

<ANY
  ng-mouseenter="expression">
...
</ANY>
<ANY
  ng-mousemove="expression">
...
</ANY>

参数

参数范例概况
ngMouseenterexpression表达式在鼠标进入元素时被触发(事宜对象与$event一样可取得)
ngMousemoveexpression表达式在鼠标在元素上挪动时被触发(事宜对象与$event一样可取得)

ngMouseover/ngMouseleave

用法

<ANY
  ng-mouseover="expression">
...
</ANY>
<ANY
  ng-mouseleave="expression">
...
</ANY>

参数

参数范例概况
ngMouseoverexpression表达式在鼠标穿过元素时被触发(事宜对象与$event一样可取得)
ngMouseleaveexpression表达式在鼠标脱离时被触发(事宜对象与$event一样可取得)

ngSelected

用法

<OPTION
  ng-selected="expression">
...
</OPTION>

参数

参数范例概况
ngSelectedexpression表达式为真时,selected属性将被设置在元素上。

ngSubmit

用法

<form
  ng-submit="expression">
...
</form>

参数

参数范例概况
ngSubmitexpression提交表单时,表达式被触发(事宜对象与$event一样可取得)

综合实例

html代码

<div ng-app="myapp">
    <form name="form" ng-controller="formCtrl">
        <p>
            <input type="text" ng-model="blur" ng-blur="blur='be blured'" ng-focus="blur='got focus,click other place'" placeholder="click me" />
        </p>
        <p>
            <span ng-model="mouseEvent" ng-mouseenter="mouseEvent='mouseenter'" ng-mouseleave="mouseEvent='mouseleave'" ng-bind="mouseEvent" ng-init="mouseEvent='touch me'">touch me</span>
        </p>
        <p>
            <input type="text" ng-model="change" ng-change="changeEvent()" placeholder="change me" />
        </p>
        <p>
            msg1:{{changeStatus}},content:{{change}}
        </p>
        <p>
            <input type="button" ng-click="btnClickChangeCheckboxEvent()" value="change status of checkbox->" />
            <input type="checkbox" ng-model="checkbox" ng-checked="isStatus" />
        </p>
        <p>
            <input type="checkbox" ng-model="option" />change status of select
            <select>
                <option>A</option>
                <option ng-selected="option">B</option>
            </select>
        </p>
    </form>
</div>

js代码

angular.module('myapp', [])
    .controller('formCtrl', function($scope) {
        $scope.change = 'change me';
        $scope.changeStatus = 'no change';
        $scope.isStatus = false;
        $scope.option = false;

        $scope.changeEvent = function() {
            $scope.changeStatus = 'be changed';
        }

        $scope.btnClickChangeCheckboxEvent = function() {
            $scope.isStatus = !$scope.isStatus;
        }
    });

DEMO地点:https://jsfiddle.net/Lionney/vLkoz9d3/

若有题目,请斧正。

    原文作者:大猛
    原文地址: https://segmentfault.com/a/1190000004536757
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞