angular.js - angular ng-focus ng-blur 存在問題
問題描述
-.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, 求解。
續(xù):
老衲服了,貼出項目代碼如下:
-.html
<p class='form-group'><label class='form-label'>應用名:</label><span ng-show='applyTips' ng-init='applyTips = true'> 應用名是您將要創(chuàng)建的應用的名稱,組織內(nèi)唯一</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; }};
input失去焦點后,提示信息不再顯示。
問題解答
回答1:ng-blur 里面寫表達式就行ng-blur='isHide'
在控制器中對isHide賦值$scope.isHide=true;
同理ng-focus里面也一樣
官網(wǎng)文檔
回答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:{} }}
打開控制臺看下錯誤信息就能解決了。
相關(guān)文章:
1. css - 新手做響應式布局, 斷點過后右側(cè)出現(xiàn)空白,求幫助,謝謝。2. javascript - 關(guān)于<a>元素與<input>元素的JS事件運行問題3. javascript - ES6 中能否把 class 屬性 方法 分文件?4. python - 能通過CAN控制一部普通的家用轎車嗎?5. mysql - 查詢字段做了索引為什么不起效,還有查詢一個月的時候數(shù)據(jù)都是全部出來的,如果分拆3次的話就沒問題,為什么呢。6. mysql - 記得以前在哪里看過一個估算時間的網(wǎng)站7. ID主鍵不是自增的嗎 為什么還要加null8. 大家好,我想請問一下怎么做搜索欄能夠搜索到自己網(wǎng)站的內(nèi)容。9. MySQL中的enum類型有什么優(yōu)點?10. css - 關(guān)于border-image
