AngularJS的form状态变色
代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsChangeFormClass.rar
代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html ng-app="notesApp">
<head>
<title> New Document </title>
<style>
.username.ng-valid{
background-color:lightgreen;
}
.username.ng-dirty.ng-invalid-required{
background-color:red;
}
.username.ng-dirty.ng-invalid-minlength{
background-color:lightpink;
}
</style>
<meta charset="utf-8">
<script src="angular1.4.6.min.js"></script>
</head>
<body ng-controller="MainCtrl as ctrl">
<form ng-submit="ctrl.submit()" name="myForm">
<table>
<tr>
<td><input type="text" class="username" name="uname" ng-model="ctrl.user.username" required ng-minlength="4"/></td>
<td>
<span ng-show="myForm.uname.$error.required">This a required field</span>
<span ng-show="myForm.uname.$error.minlength">Minimum length required is 4</span>
<span ng-show="myForm.uname.$invalid">This field is invalid</span>
</td>
</tr>
<tr>
<td><input type="password" name="pwd" ng-model="ctrl.user.password" required/></td>
<td>
<span ng-show="myForm.pwd.$error.required">This a required field</span>
</td>
</tr>
<tr>
<td><input type="submit" value="Submit" ng-disabled="myForm.$invalid"/></td>
<td>
</tr>
</table>
</form>
</body>
</html>
<script type="text/javascript">
<!--
angular.module('notesApp',[])
.controller('MainCtrl',[function(){
var self=this;
self.submit=function(){
console.log("Username="+self.user.username+" Password="+self.user.password);
alert("Form submitted.");
};
}]);
//-->
</script>
效果:


AngularJS的form状态变色的更多相关文章
- 【Winform-GataGridView】根据DataGridView中的数据内容设置行的文字颜色、背景色 — 根据状态变色
C#中可以根据每行内容的不同来对DataGridView数据表格控制每行的文字颜色.背景颜色进行不同的设置. 效果如下: 实现: 在DataGridView的RowPrePaint事件中进行行颜色控制 ...
- angular-JS模仿Form表单提交
直接上示例代码,有不懂的欢迎留言: $http({ url: "http://localhost:10086/yuanxin/Conference/ImportExcelDataForBus ...
- 【python】列出http://www.cnblogs.com/xiandedanteng中所有博文的标题
代码: # 列出http://www.cnblogs.com/xiandedanteng中所有博文的标题 from bs4 import BeautifulSoup import requests u ...
- Node.js 网页爬虫再进阶,cheerio助力
任务还是读取博文标题. 读取app2.js // 内置http模块,提供了http服务器和客户端功能 var http=require("http"); // cheerio模块, ...
- Node.js 网页瘸腿稍强点爬虫再体验
这回爬虫走得好点了,每次正常读取文章数目总是一样的,但是有程序僵住了情况,不知什么原因. 代码如下: // 内置http模块,提供了http服务器和客户端功能 var http=require(&qu ...
- Node.js 网页瘸腿爬虫初体验
延续上一篇,想把自己博客的文档标题利用Node.js的request全提取出来,于是有了下面的初哥爬虫,水平有限,这只爬虫目前还有点瘸腿,请看官你指正了. // 内置http模块,提供了http服务器 ...
- AngularJS(一)
什么是AngularJS[双向数据绑定:从界面的操作能实时反映到数据,数据的变更能实时展现到界面.]?1.AngularJS 使得开发现代的单一页面应用程序(SPAs:Single Page Appl ...
- AngularJS:模型
ylbtech-AngularJS:模型 1.返回顶部 1. AngularJS ng-model 指令 ng-model 指令用于绑定应用程序数据到 HTML 控制器(input, select, ...
- AngularJS(五):表单及输入验证
本文也同步发表在我的公众号“我的天空” 表单基础 表单是HTML中很重要的一个部分,基本上我们的信息录入都依靠表单,接下来我们学习如何在AngularJS中使用表单,首先看以下示例代码: <bo ...
随机推荐
- appium安装,和遇到的问题
https://www.cnblogs.com/fnng/p/4540731.html Appium环境搭建时在cmd中输入appium-doctor命令,提示’appium-doctor’ 不是内部 ...
- linux随笔一
1.过滤列表输出:*表示多个字符 ll mon* 结果输出为:mongo.sh mongo_sso.sh 2.man +命令 例如:man ls 查看命令的用法 3.cd 将shell回话移动到 ...
- pip安装及使用
1.pip下载安装 1.1 pip下载 # wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5= ...
- 聊聊、Nginx 初始化日志文件
我们接着上一篇文章继续来看看 ngx_regex_init()函数.搜索 ngx_regex_init 得到位置为src/core/ngx_regex.c:ngx_regex_init(void). ...
- rails提供的validators
Instance Public methods attribute_method?(attribute)Link Returns true if attribute is an attribute m ...
- 一句话学Java——Java重载和重写
概念:重载是指两个不同的函数有相同的名称,可以是在本类之中的函数之间的重载,也可以是子类和父类的函数之间的函数重载. 重写:只能是子类重写父类的函数.这是多态的基础. 重写的规则: 参数:重写 ...
- P1875 佳佳的魔法药水 (最短路,DP)
题目链接 Solution 好题. 一开始一直在想怎么蛇皮建图,但是发现一直蛇不出来... 正解是用类似于 dijkstra 的算法对所有点进行松弛. 对于每个元素记录两个值: \(cost\) 代表 ...
- 《如何成为一位大家愿意追随的Leader》读后感
今天看了左耳朵耗子老师的文章<如何成为一位大家愿意追随的Leader>深有感触.每一行字都往心里说,文章里说到Leader和Boss的不同点在于,Leader是大家跟我一起上,而Boss则 ...
- C#精髓第四讲 GridView 72般绝技
原文发布时间为:2008-08-03 -- 来源于本人的百度文章 [由搬家工具导入] 原文地址:http://blog.csdn.net/21aspnet/archive/2007/03/25/154 ...
- ajax cache enable and ajax concurrency!
Today, forget to close ajax cache which leads to duplicate result from cache as to Jquery, this way, ...