加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS:简单的模糊功能

发布时间:2020-12-17 18:01:22 所属栏目:安全 来源:网络整理
导读:我是AngularJS的新手.从W3school学到的.现在开始了解模糊功能和ui-event如何在其他网站上运行.所以我得到的代码不起作用请让我知道原因或更好的方法来调用模糊功能. HTML div ng-app="" ng-controller="testing" input ui-event="{ blur : 'blurCallback()'
我是AngularJS的新手.从W3school学到的.现在开始了解模糊功能和ui-event如何在其他网站上运行.所以我得到的代码不起作用请让我知道原因或更好的方法来调用模糊功能.

HTML

<div ng-app="" ng-controller="testing" >
    <input ui-event="{ blur : 'blurCallback()' }">
    </div>

脚本标记

function testing($scope){
    $scope.blurCallback = function() {
    alert('Goodbye');
    };
}

解决方法

我建议使用AngularJS框中的ngBlur.

该指令从Angular的1.2版本开始提供.

<div ng-controller="MyCtrl">
    <input type="text" ng-model="blurModel" ng-blur="onBlur($event)"/>
</div>

function MyCtrl($scope) {
    $scope.onBlur = function($event) {
        console.log($event);
    }
}

我为你附上了JSFiddle的例子.

如果要使用UI.Utils库,则应将“ui.utils”模块注入项目.

var app = angular.module('plunker',['ui.utils']);

app.controller('MainCtrl',function($scope) {
    $scope.onBlur = function($event) {
        console.log($event);
    };
});

<body ng-controller="MainCtrl">
    <input type="text" placeholder="ui-utils" ui-event="{blur:'onBlur($event)'}"/>
</body>

这是一个使用ui.utils的Plunker.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读