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, 求解。
續:
老衲服了,貼出項目代碼如下:
-.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; }};
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:{} }}
打開控制臺看下錯誤信息就能解決了。
相關文章:
1. javascript - js 有什么優雅的辦法實現在同時打開的兩個標簽頁間相互通信?2. css3 - Typecho 后臺部分表單按鈕在 Chrome 下出現靈異動畫問題,求解決3. java - 新手做一個安卓視頻播放器,想實現一個進度條,按鈕那種在視頻下方懸浮的功能,不知道思路!4. javascript - jquery怎么給select option一個點擊時觸發的事件,如圖 如果選擇自定義觸發一個時間?5. nginx配置server模塊的問題6. java - android代碼重構:如何把app設置里的頭像UI做成通用的?7. node.js - express請求的具體方法8. javascript - angular和jquery都用到了$符號,一起用會不會沖突?9. 想找個php大神仿個網站。10. javascript - 怎樣限制同一個瀏覽器不能登錄兩個賬號
