zoukankan      html  css  js  c++  java
  • 用angular中的angular-messages(ngMessage)实现表单验证时输入框外提示信息的显示与隐藏(直接把代码粘贴到新建的html文件中即可实现)

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="//cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="//cdn.bootcss.com/angular.js/1.5.8/angular.min.js"></script>
    <script src="//cdn.bootcss.com/angular-messages/1.5.8/angular-messages.min.js"></script>
    </head>
    <body ng-app="myApp">

    <div class="container">
    <div class="col-md-4 col-md-offset-4">
    <form class="form-horizontal" novalidate name="signupForm" ng-controller="SignupController">
    <div class="form-group" ng-class="{'has-success': signupForm.username.$valid, 'has-error': signupForm.username.$invalid && signupForm.username.$dirty}">
    <label class="control-label">Username</label>
    <input type="text" name="username" class="form-control" ng-model="user.username" required ng-minlength="5" ng-maxlength="12">
    <div class="help-block" ng-show="signupForm.username.$dirty && signupForm.username.$error.minlength">
    用户名不能少于5个字符呀,魂淡~
    </div>
    <div class="help-block" ng-show="signupForm.username.$dirty && signupForm.username.$error.maxlength">
    用户名不能多于12个字符~魂淡
    </div>
    <!-- <pre><code>{{signupForm.username.$error}}</code></pre> -->
    </div>
    <div class="form-group" ng-class="{'has-success': signupForm.password.$valid && signupForm.password.$dirty, 'has-error': signupForm.password.$invalid && signupForm.password.$dirty}">
    <label class="control-label">Password</label>
    <input type="password" name="password" class="form-control" ng-model="user.password" ng-required="required" ng-minlength="6" ng-maxlength="13">
    <div class="help-block" ng-messages="signupForm.password.$dirty && signupForm.password.$error">
    <div ng-message="required">魂淡!密码不能为空!</div>
    <div ng-message="minlength">魂淡!密码不能少于6个字符</div>
    <div ng-message="maxlength">魂淡~密码需要那么长么~!</div>
    </div>
    </div>
    <div class="form-group">
    <button type="button" class="btn btn-success form-control">提交</button>
    </div>
    </form>
    </div>
    </div>

    <script>
    var app = angular.module('myApp', ['ngMessages']);
    app.controller('SignupController', ['$scope', function($scope){
    $scope.user = {};
    $scope.required = true;
    console.log(signupForm.$error);
    }])
    </script>
    </body>
    </html>

  • 相关阅读:
    Linq之旅:Linq入门详解(Linq to Objects)【转】
    Shadow Map 原理和改进 【转】
    OSG 中文解决方案 【转】
    shadow mapping实现动态shadow实现记录 【转】
    RenderMonkey 练习 第六天 【OpenGL Water 水效】
    glsl水包含倒影的实现(rtt) 【转】
    Docker镜像仓库Harbor之搭建及配置
    docker登录没有配置https的harbor镜像仓库
    Git 清除远端已删除的分支
    单节点k8s的一个小例子 webapp+mysql
  • 原文地址:https://www.cnblogs.com/mgqworks/p/7484353.html
Copyright © 2011-2022 走看看