欢迎您访问我爱IT技术网,今天小编为你分享的javascript教程:【AngularJS手动表单验证】,下面是详细的讲解!
AngularJS手动表单验证
<!DOCTYPE html> <html lang="en" ng-app="myApp1"> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" href="http://www.jb51.net/article/../node_modules/bootstrap/dist/css/bootstrap.min.css"/> <link rel="stylesheet" href="http://www.jb51.net/article/../css/main.css"/> </head> <body> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <a href="http://www.jb51.net/" class="navbar-brand">Form Submitting</a> </div> </div> </nav> <div class="container main-content" ng-controller="myCtrl1"> <!--novalidate让表单不要使用html验证--> <!--theForm变成scope的一个字段--> <form ng-submit="onSubmit(theForm.$valid)" novalidate="novalidate" name="theForm"> <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" id="name" ng-model="formModel.name"/> </div> <div class="form-group" ng-class="{ 'has-error': !theForm.email.$valid && (!theForm.$pristine || theForm.$submitted), 'has-success': theForm.email.$valid && (!theForm.$pristine || theForm.$submitted) }"> <label for="email">Email</label> <input type="email" class="form-control" id="email" ng-model="formModel.email" required="required" name="email"/> <p class="help-block" ng-show="theForm.email.$error.required && (!theForm.$pristine || theForm.$submitted)">必填</p> <p class="help-block" ng-show="theForm.email.$error.email && (!theForm.$pristine || theForm.$submitted)">email格式不正确</p> </div> <div class="form-group"> <label for="username">Username</label> <input type="text" class="form-control" id="username" ng-model="formModel.username"/> </div> <div class="form-group"> <label for="age">Age</label> <input type="number" class="form-control" id="age" ng-model="formModel.age"/> </div> <div class="form-group"> <label for="sex">Sex</label> <select name="sex" id="sex" class="form-control" ng-model="formModel.sex"> <option value="">Please choose</option> <option value="male">Mail</option> <option value="femail">Femail</option> </select> </div> <div class="form-group"> <label for="password">Password</label> <input type="text" class="form-control" id="password" ng-model="formModel.password"/> </div> <div class="form-group"> <button class="btn btn-primary" type="submit">Register</button> </div> <pre> {{theForm | json}} </pre> </form> </div> <script src="http://www.jb51.net/article/../node_modules/angular/angular.min.js"></script> <script src="http://www.jb51.net/article/second.js"></script> </body> </html>
关于AngularJS手动表单验证的用户互动如下:
相关问题:表单验证
答:onload=function(){ function aa(){return false} } 这种用法本身就是错的; 要知道,我们所编写的某个函数,比如在script标签中直接写入一个函数: function fun(){} 那么,这个fun()函数是windows对象下的; 如果你写成: onload = function()... >>详细
相关问题:用angularjs表单验证怎么写
答:客户端表单验证是AngularJS里面最酷的功能之一。 AngularJS表单验证可以让你从一开始就写出一个具有交互性和可相应的现代HTML5表单。 在AngularJS中,有许多表单验证指令。 在这里,我们将谈谈几个最流行指令,然后我们将讨论如何编写自定义的验... >>详细
相关问题:angularjs 表单验证 提示 文本框怎么没有红的
答:客户端表单验证是AngularJS里面最酷的功能之一。 AngularJS表单验证可以让你从一开始就写出一个具有交互性和可相应的现代HTML5表单。 在AngularJS中,有许多表单验证指令。 在这里,我们将谈谈几个最流行指令,然后我们将讨论如何编写自定义的验... >>详细
- 【Array】js中更短的 Array 类型转换-类型转换
- 【ExtJs】ExtJs 表单提交登陆实现代码-表单提交-
- 【Ajax】jQuery 学习第六课 实现一个Ajax的TreeVi
- 【extjs】extjs每个组件要设置唯一的ID否则会出错
- 【focus】JavaScript使用focus()设置焦点失败的解
- 【bootstrap3】基于bootstrap3和jquery的分页插件
- 【hover】jQuery控制图片的hover效果(smartRollo
- 【ajax更新数据库】ajax异步刷新实现更新数据库-
- 【div】div浮层 滚动条移动 位置保持不变的4种方
- 【AngularJS】举例讲解AngularJS中的模块-模块
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
