简体   繁体   English

如何检查输入字段的文本是“是”还是“否”?

[英]How can I check if the text of an input field is “yes” or “no”?

I want to check if the text from the input field isAdmin is "yes" or "no". 我想检查来自输入字段isAdmin的文本是“是”还是“否”。 Is it possible to do this with ng-click ? 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>

These are the input fields and when I press on the button "Speichern", I want to check it. 这些是输入字段,当我按“ Speichern”按钮时,我要检查它。

What is the problem to check your inputs on ng-click handler? 检查ng-click处理程序上的输入有什么问题?

if ($scope.currentUser.login && $scope.currentUser.login.toLowerCase() ==='yes') {
console.log('that is it');
}

UPDATED: 更新:

If you have time, Ill advice you to read about ng-model controller . 如果有时间,我会建议您阅读有关ng-model controller的文章 Filds validation is his responosibility and it have a lot of tools for this. 实地验证是他的责任,它为此提供了很多工具。

You can check those values inside your saveUser() function. 您可以在saveUser()函数中检查这些值。 For example: 例如:

//Inside your controller:
$scope.saveUser = function () {
    if ($scope.currentUser.login && $scope.currentUser.login.toLowerCase() === 'yes') {
        //do something
    } else {
        //do something else/display error 
    }
}

You can check all values you need this way 您可以通过这种方式检查所需的所有值

I made it like this and it works! 我做到了,这样行得通!

JavaScript: 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: HTML:

     <button class="cButtonSpeichern" ng-click="showAlert()">Speichern</button>

but thank you for your help guys! 但是谢谢您的帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在 html 表单输入字段中显示我的文本文件数据吗? 如果是,请告诉我怎么做? - can i display my text file data in html form input field? if yes, please tell me how? 如何将文本输入镜像到登录名和密码输入。 (是的,它们是一样的) - How can I mirror a text input to a login and password input. (Yes they are the same) 如何检查js上的输入字段并根据文本值编写和回答 - How can I check the input field on js and write and answer based on the text value 如何检查输入字段是否包含有效文本而不是表单中的随机字符? - How can I check if input field contains valid text instead of random characters in a form? 如何将输入文本字段替换为跨度文本? - how can I replace input text field into text in span? 我如何将文本更改为单击文本本身的输入字段 - How can I change text to input field clicking on the text itself 给定两个是/否字段,当字段 1 值被选中“是”时,如何使用 JavaScript 使字段 2 值被选中“是”? - Given two yes/no fields, how can I use JavaScript to make the field 2 value checked "Yes" whenever the field 1 value is checked "Yes"? 如何检查vue.js中的输入字段是否集中? - How can I check focused or not a input field in vue.js? 如何检查按键上文本字段的新值? - How can I check the new value of a text field on keypress? 如何检查文本字段值的格式是否正确? - How can I check if a text field value has the correct format?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM