您的位置:首页技术文章
文章详情页

angular.js - angular ng-focus ng-blur 存在问题

【字号: 日期:2024-09-25 13:34:13浏览:71作者:猪猪

问题描述

-.html

<input type='text' ng-focus='display = false' ng-blur='display = true' ng-init='display = true'><p ng-show='display'>aaa</p>

如上述代码,focus/blur可以正常控制p标签的显示与隐藏

-.html

<input type='text' ng-focus='display = false' ng-blur='hide()' ng-init='display = true'><p ng-show='display'>aaa</p>

-controller.js

$scope.hide = function (){ $scope.display = true;};

上述代码只要focus input,display一直为false, 求解。

续:

老衲服了,贴出项目代码如下:

-.html

<p class='form-group'><label class='form-label'>应用名:</label><span ng-show='applyTips' ng-init='applyTips = true'> 应用名是您将要创建的应用的名称,组织内唯一</span> <span ng-show='applyNameExit'>应用名已存在,请重新输入</span> <span ng-show='login.applyName.$error.pattern'>您的应用名不正确</span> <p class='controls'> <input type='text' name='applyName' ng-model='param.deployment.metadata.name' ng-pattern='/^[a-z0-9]([-a-z0-9]*[a-z0-9])?$/' ng-focus='applyTips=false' ng-blur='login.applyName.$error.pattern ? applyTips = false : nameIsExit();' required></p> </p>

-controller.js

$scope.nameIsExit = function (){ if($scope.param.deployment.metadata.name !=’’ && $scope.param.deployment.metadata.name != undefined){var param = { orgId: $localStorage.orgId, userId: $localStorage.userId, sessionId: $localStorage.sessionId, 'name': $scope.param.deployment.metadata.name};deploymentService.applyNameisExit(param, function(res){ if(res.code == 1415){$scope.applyTips = false;$scope.applyNameExit = true;$scope.submit = function(){ return;}}else{$scope.applyTips = true;$scope.applyNameExit = false;}}); } else{$scope.applyTips = true; }};

angular.js - angular ng-focus ng-blur 存在问题

angular.js - angular ng-focus ng-blur 存在问题

input失去焦点后,提示信息不再显示。

问题解答

回答1:

ng-blur 里面写表达式就行ng-blur='isHide'

在控制器中对isHide赋值$scope.isHide=true;

同理ng-focus里面也一样

官网文档

回答2:

这位少年,我怀疑你姿势有问题。

<body ng-app='myApp'> <p ng-controller='MyCtrl'> <input type='text' ng-focus='display = false' ng-blur='hide()' ng-init='display = true'> <p ng-show='display'>aaa</p> </p> <script type='text/javascript'>var app = angular.module(’myApp’, []);app.controller(’MyCtrl’,function($scope){ $scope.hide = function (){$scope.display = true; }}); </script></body>

如果还有问题,我保证让你自切jj

-------------------------------呵呵哒---------------------------------------

$scope.param = { deployment:{metadata:{} }}

打开控制台看下错误信息就能解决了。

相关文章: