Angular.js通过bootstrap实现经典的表单提交
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="//apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body ng-app="myApp" ng-controller="userCtrl"> <div class="container"> <h3>Users</h3> <table class="table table-striped">
<thead>
<tr>
<th>编辑</th>
<th>名</th>
<th>姓</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="user in users">
<td>
<button class="btn" ng-click="editUser(user.id)" >
<span class="glyphicon glyphicon-pencil"></span>编辑
</button>
</td>
<td>{{ user.fName }}</td>
<td>{{ user.lName }}</td>
</tr>
</tbody>
</table> <hr>
<button class="btn btn-success" ng-click="editUser('new')">
<span class="glyphicon glyphicon-user"></span>创建新用户
</button>
<hr> <h3 ng-show="edit">创建新用户:</h3>
<h3 ng-hide="edit">编辑用户:</h3> <form class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">名:</label>
<div class="col-sm-10">
<input type="text" ng-model="fName" ng-disabled="!edit" placeholder="名">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">姓:</label>
<div class="col-sm-10">
<input type="text" ng-model="lName" ng-disabled="!edit" placeholder="姓">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">密码:</label>
<div class="col-sm-10">
<input type="password" ng-model="passw1" placeholder="密码">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">重复密码:</label>
<div class="col-sm-10">
<input type="password" ng-model="passw2" placeholder="重复密码">
</div>
</div>
</form> <hr>
<button class="btn btn-success" ng-disabled="error || incomplete">
<span class="glyphicon glyphicon-save"></span>修改
</button> </div> <script src="test.js"></script> </body>
</html>
var app=angular.module('myApp',[]);
app.controller('userCtrl',function($scope){
$scope.fName='';
$scope.lName='';
$scope.passw1='';
$scope.passw2='';
$scope.users=[
{id:1,fName:'Hege',lName:'Pege'},
{id:2,fName:'Kim',lName:'Pim'},
{id:3,fName:'Sal',lName:'Smith'},
{id:4,fName:'Jack',lName:'Jones'},
{id:5,fName:'John',lName:'Doe'},
{id:6,fName:'Peter',lName:'Pan'},
];
$scope.edit=true;
$scope.error=false;
$scope.incomplete=false;
$scope.editUser=function(id){
if(id=='new'){
$scope.edit=true;
$scope.incomplete=true;
$scope.fName='';
$scope.lName='';
}else{
$scope.edit=false;
$scope.fName=$scope.users[id-1].fName;
$scope.lName=$scope.users[id-1].lName;
}
};
$scope.$watch('passw1',function(){
$scope.test();
});
$scope.$watch('passw2',function(){
$scope.test();
});
$scope.$watch('fName',function(){
$scope.test();
});
$scope.$watch('lName',function(){
$scope.test();
});
$scope.test=function(){
if($scope.passw1!==$scope.passw2){
$scope.error=true;
}else{
$scope.error=false;
}
$scope.incomplete=false;
if($scope.edit&&(!$scope.fName.length)||!$scope.lName.length||
!$scope.lName.length||!$scope.passw1.length||!$scope.passw2.length
){
$scope.incomplete=true;
}
}
});

Angular.js通过bootstrap实现经典的表单提交的更多相关文章
- 使用RequireJs和Bootstrap模态框实现表单提交
下面我将使用requirejs结合模态框实现三五行代码部署表单提交操作. 传统开发思路如下:
- js判断checkbox状态,处理表单提交事件
功能描述:手机网页需要一个投票功能,通过form的post提交.有5-20个checkbox选项,至少选一项,至多选三项.需要在用户点击提交按钮前,判断checkbox的状态是否符合条件,符合则提交到 ...
- form表单提交过程
本文为转载文章! 今天,我将站在HTML和单纯的Asp.net框架的角度来解释它们的工作方式,因此,本文不演示WebForms服务器控件的相关内容. 简单的表单,简单的处理方式 好了,让我们进入今天的 ...
- koa 基础(十一)koa 中 koa-bodyparser 中间件获取表单提交的数据
1.app.js /** * koa 中 koa-bodyparser 中间件获取表单提交的数据 * 1.npm install --save koa-bodyparser * 2.引入 const ...
- 原生JS 表单提交验证器
转载:http://www.cnblogs.com/sicd/p/4613628.html 一.前言 最近在开发一个新项目,需要做登陆等一系列的表单提交页面.在经过“缜密”的讨论后,我们决定 不用外部 ...
- Bootstrap -- 表格样式、表单布局
Bootstrap -- 表格样式.表单布局 1. 表格的一些样式 举例: <!DOCTYPE html> <html> <head> <meta http- ...
- 基于Bootstrap+jQuery.validate Form表单验证实践
基于Bootstrap jQuery.validate Form表单验证实践 项目结构 : github 上源码地址:https://github.com/starzou/front-end- ...
- Angular Reactive Forms -- Model-Driven Forms响应式表单
Angular 4.x 中有两种表单: Template-Driven Forms - 模板驱动式表单 (类似于 AngularJS 1.x 中的表单 ) 官方文档:https://v2.angul ...
- Bootstrap历练实例:表单帮助文件
Bootstrap表单控件可以在输入框input上有一个块级帮助文本,为了添加一个占用整个宽度的内容块,请在input后添加help-block. 实例: <!DOCTYPE html>& ...
随机推荐
- Microsoft SQL Server 2005 Service fails to start
今天碰到一雷死人的事情,在Windows Server 2012 R2上安装SQL SERVER 2005标准版过程中一直遇到"The SQL Server service failed t ...
- Linux命令学习总结:hexdump
命令简介: hexdump是Linux下的一个二进制文件查看工具,它可以将二进制文件转换为ASCII.八进制.十进制.十六进制格式进行查看. 指令所在路径:/usr/bin/hexdump 命令语法: ...
- RAC异机恢复
RAC异机恢复PDCL到PFCL: PNCL:RAC+ASM ,product env db name:PNCL instance:PDCL1 PDCL2 PFCL:RAC+ASM ,perf ...
- Terminate Instance 操作详解 - 每天5分钟玩转 OpenStack(33)
本节通过日志详细分析 Nova Terminate 操作. Terminate 操作就是删除 instance,下面是 terminate instance 的流程图 向 nova-api 发送请求 ...
- 强大的DOM变化观察者MutationObserver
在这之前 DOM3 提供了 Mutation events 事件 DOMAttrModified DOMAttributeNameChanged DOMCharacterDataModified DO ...
- ELF Format 笔记(十二)—— 段类型(segment types)
ilocker:关注 Android 安全(新手) QQ: 2597294287 PT_NULL:如果段类型是 PT_NULL,那相应程序头结构体的其它成员都无意义,该程序头项可被忽略. 暂时还没遇到 ...
- EF optimize the perfermance
参考 Three steps for fast entityframework 6.1 code-first startup performance Managing DbContext ...
- 使用VNET-to-VNET连接Microsoft Azure国际版和中国版
Microsoft Azure的VNET-to-VNET功能可以实现跨虚拟网络的VPN连接,通过VNET-to-VNET互联的两个虚拟网络可以在同一个订阅下或者隶属不同的订阅,而且可以跨数据中心.这实 ...
- [转]ASP.NET Core 之 Identity 入门(二)
本文转自:http://www.cnblogs.com/savorboard/p/aspnetcore-identity2.html 前言 在 上篇文章 中讲了关于 Identity 需要了解的单词以 ...
- On having layout
英文原文在此:http://www.satzansatz.de/cssd/onhavinglayout.htm 介绍 Internet Explorer 中有很多奇怪的渲染问题可以通过赋予其“layo ...