我得到了兩個元素段落和輸入標籤。當我點擊段落時,輸入應該顯示,段落應該隱藏。當輸入模糊時,應該隱藏輸入並顯示段落。 我試過,但沒有工作角度隱藏模糊元素
<p ng-click="edit = true" ng-show="!edit">some text</p>
<div ng-show="edit" ng-blur="edit = false">
<input type=text name="email" ng-blur="blurUpdate()" />
</div>
我得到了兩個元素段落和輸入標籤。當我點擊段落時,輸入應該顯示,段落應該隱藏。當輸入模糊時,應該隱藏輸入並顯示段落。 我試過,但沒有工作角度隱藏模糊元素
<p ng-click="edit = true" ng-show="!edit">some text</p>
<div ng-show="edit" ng-blur="edit = false">
<input type=text name="email" ng-blur="blurUpdate()" />
</div>
移動ng-blur
到input
請看演示下面
var app = angular.module('app', []);
app.controller('homeCtrl', function($scope, $timeout) {
$scope.showEditor = function() {
$scope.edit = true;
var textbox = document.getElementById("input_email");
var tmp = $scope.text
$scope.text = ""
$timeout(function() {
textbox.focus();
$scope.text = tmp;
});
}
$scope.blurUpdate = function() {
// add this line
$scope.edit = false;
//your code
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="homeCtrl" ng-init="text='some text'">
<p ng-click="showEditor()" ng-show="!edit">{{text}}</p>
<div ng-show="edit">
<input type=text name="email" ng-blur="blurUpdate()" ng-model="text" id="input_email" />
</div>
</div>
</div>
對不起,我沒有提到我有輸入模糊中的另一個功能。如何設置。問題編輯 – 2014-11-03 11:09:29
@AbelD請看更新的回答 – sylwester 2014-11-03 11:14:39
它的顯示。好,但我也需要它的重點。現在我需要點擊兩次才能獲得輸入焦點。 – 2014-11-03 12:08:43
的ngBlur與輸入標籤兼容,這就是爲什麼它不工作:
<p ng-click="edit = true" ng-show="!edit">some text</p>
<div ng-show="edit" >
<input type=text ng-blur="edit = false" name="email" />
</div>
對不起,我沒有提到我有輸入模糊的另一個功能。如何設置。編輯問題 – 2014-11-03 11:08:56
然後你應該改變方法: http://jsfiddle.net/xgp2qsww/3/ div上的ngBlur沒有用。函數blurUpdate必須更改$ scope.edit才能執行您所尋求的 – Michael 2014-11-03 11:18:37
其顯示。好,但我也需要它的重點。現在我需要點擊兩次才能獲得輸入焦點。 – 2014-11-03 12:08:14
這是問題中的拼寫錯誤,還是您真的忘記了'ng-blur'之後的'='?另外,嘗試將'ng-blur'放在'input'而不是'div'上。 – sp00m 2014-11-03 10:52:38
對不起,它有一個錯字。我在div裏面有圖標。我希望他們太隱藏。 – 2014-11-03 11:03:50