![](/img/trans.png)
[英]can i display my text file data in html form input field? if yes, please tell me how?
[英]How can I check if the text of an input field is “yes” or “no”?
我想檢查來自輸入字段isAdmin的文本是“是”還是“否”。 用ng-click
可以做到嗎?
<div class="cClearFloat cInputSpace">
<input placeholder="login" ng-model="currentUser.login">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Vorname" ng-model="currentUser.Vorname">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Nachname" ng-model="currentUser.Nachname">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="password" ng-model="currentUser.password">
</div>
<div class="cClearFloat cInputSpace">
<input placeholder="Admin" ng-model="currentUser.isAdmin">
</div>
<div class="cClearFloat cButtonsUser">
<button class="cButtonSpeichern" ng-click="saveUser()">Speichern</button>
<button class="cButtonAbbrechen" ng-click="isShownUser= false">Abbrechen</button>
</div>
</div>
這些是輸入字段,當我按“ Speichern”按鈕時,我要檢查它。
檢查ng-click處理程序上的輸入有什么問題?
if ($scope.currentUser.login && $scope.currentUser.login.toLowerCase() ==='yes') {
console.log('that is it');
}
更新:
如果有時間,我會建議您閱讀有關ng-model controller的文章 。 實地驗證是他的責任,它為此提供了很多工具。
您可以在saveUser()函數中檢查這些值。 例如:
//Inside your controller:
$scope.saveUser = function () {
if ($scope.currentUser.login && $scope.currentUser.login.toLowerCase() === 'yes') {
//do something
} else {
//do something else/display error
}
}
您可以通過這種方式檢查所需的所有值
我做到了,這樣行得通!
JavaScript:
$scope.showAlert = function() {
//überprüfen ob die textfelder leer sind
if ($scope.currentUser.isAdmin == 'Ja' | $scope.currentUser.isAdmin == 'ja') {
$scope.isAdmin = "Ja";
$scope.saveUser();
} else if($scope.currentUser.isAdmin == 'Nein' | $scope.currentUser.isAdmin == 'nein') {
$scope.isAdmin = "Nein";
$scope.saveUser();
} else {
alert("Bitte geben Sie ein ob der Benutzer ein Admin ist oder nicht!", "Fehler");
}
}
HTML:
<button class="cButtonSpeichern" ng-click="showAlert()">Speichern</button>
但是謝謝您的幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.