<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="../bootstrap/html5shiv.min.bootstrap"></script>
<script src="../bootstrap/respond.min.bootstrap"></script>
<![endif]-->
<script src="../scripts/jquery-1.12.2.min.js"></script>
<script src="../bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container"> <div class="row">
<div class="col-sm-6 col-sm-offset-3">
<h2 class="page-header">注册</h2>
<form class="form-horizontal" action="bootstrap表单带验证.html" method="get">
<div class="form-group has-feedback">
<label for="email" class="col-sm-2 control-label">Email </label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" placeholder="Email" required>
<span class=""></span>
</div>
</div>
<div class="form-group has-feedback">
<label for="username" class="col-sm-2 control-label">username</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="username" placeholder="username" required>
<span class=""></span>
</div>
</div>
<div class="form-group has-feedback">
<label for="password" class="col-sm-2 control-label">password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password" placeholder="password" required>
<span class=""></span>
</div>
</div>
<p class="text-right">
<button id="btnSubmit" type="submit" class="btn btn-primary">submit</button>
<button type="reset" class="btn btn-danger">reset</button>
</p>
</form>
</div>
</div> </div>
<script>
function checkInput(txt){
if(txt.val()==""){
// alert(txt.parent().parent().html()); alert html
txt.parent().parent() /*找到父类 先删除样式,再添加样式*/
.removeClass()
.addClass("form-group has-error has-feedback");
txt.next().removeClass()
.addClass("glyphicon glyphicon-remove form-control-feedback");
return false;
}else{
txt.parent().parent().removeClass().addClass("form-group has-success has-feedback");
txt.next().removeClass().addClass("glyphicon glyphicon-ok form-control-feedback");
return true;
}
}
function checkBind(id){
$(id).bind("blur", function () {
checkInput(id);
});
}
$().ready(function () {
checkBind($("#email"));
checkBind($("#username"));
checkBind($("#password"));
/* $("#email").bind("change", function () {
checkInput($("email"));
});*/ /* $("#email").change(function () {checkInput($("#email"));});
$("#username").change(function () {checkInput($("#username"));});
$("#password").change(function () {checkInput($("#password"));});*/ $("#btnSubmit").bind('click', function () {
if(checkInput($("#email"))&&checkInput($("#username"))&&checkInput($("#password"))){
return true;
}
return false;
})
});
</script> </body>
</html>

bootstrap表单带验证的更多相关文章

  1. Bootstrap 表单控件状态(验证状态)

    在制作表单时,不免要做表单验证.同样也需要提供验证状态样式,在Bootstrap框架中同样提供这几种效果.1..has-warning:警告状态(黄色)2..has-error:错误状态(红色)3.. ...

  2. bootstrapValidator.js,最好用的bootstrap表单验证插件

    前言:做Web开发的我们,表单验证是再常见不过的需求了.友好的错误提示能增加用户体验.博主搜索bootstrap表单验证,搜到的结果大部分都是文中的主题:bootstrapvalidator.今天就来 ...

  3. 基于Bootstrap表单验证

    基于Bootstrap表单验证 GitHub地址:https://github.com/chentangchun/FormValidate 使用方式: 1.CSS样式 .valierror { bor ...

  4. EasyUI加zTree使用解析 easyui修改操作的表单回显方法 验证框提交表单前验证 datagrid的load方法

    带参提交一次查询,从服务器加载新数据.这是一个神奇的方法 $('#dg').datagrid('load',{ code: '01', name: 'name01' }); easyui修改操作的回显 ...

  5. 详解Bootstrap表单组件

    表单常见的元素主要包括:文本输入框.下拉选择框.单选框.复选框.文本域.按钮等.下面是不同的bootstrap版本: LESS:  forms.less SASS:  _forms.scss boot ...

  6. bootstrap 表单控件 控件状态 控件大小 help-block

    bootstrap 表单控件 控件状态 控件大小 help-block <!DOCTYPE html> <html lang="en"> <head& ...

  7. HTML5表单及其验证

    随笔- 15 文章- 1 评论- 115 HTML5表单及其验证   HTML表单一直都是Web的核心技术之一,有了它我们才能在Web上进行各种各样的应用.HTML5 Forms新增了许多新控件及其A ...

  8. 测开之路一百一十一:bootstrap表单

    bootstrap表单 引入bootstrap和jquery 默认表单 垂直表单 表单属性绑定:for属性,当for的属性和id的属性相同时,单击for标签,光标自动跳到相同属性的输入框 复选框 水平 ...

  9. thinkphp表单自动验证

    ThinkPHP框架表单验证 对注册到test表的表单进行验证 在注册之前要对表单进行验证: 用户名非空验证,两次输入密码必须一致即相等验证,年龄在18~50之间即范围验证,邮箱格式正则验证. 自动验 ...

随机推荐

  1. python gui之tkinter界面设计pythonic设计

    ui的设计,控件id的记录是一件比较繁琐的事情. 此外,赋值和读取数据也比较繁琐,非常不pythonic. 有没有神马办法优雅一点呢?life is short. 鉴于控件有name属性,通过dir( ...

  2. Pólya计数定理

    我日啊..被cls的计数题虐得欲仙欲死...根本不会计数QAQ... 不懂数学啊... 前置技能 群 群是二元组\((G,*)\),满足 \(*:(G,G)\rightarrow G\) \(\exi ...

  3. 《转载》化繁为简 如何向老婆解释MapReduce?

    本文转载自http://server.zol.com.cn/329/3295529.html 昨天,我在Xebia印度办公室发表了一个关于MapReduce的演说.演说进行得很顺利,听众们都能够理解M ...

  4. ios swift generator 文章推荐

    https://medium.com/swift-programming/sequence-beyond-primitive-iterations-in-swift-80bc2507d8cc /// ...

  5. c#缓存 笔记

    1:缓存. 你需要了解大数据高并发的瓶颈在哪里,一般都是数据库层面的,机械硬盘承载不起非常快速的读写操作,cpu承载不起大量的逻辑运算,所以最基本的解决思路就是:1.换固态硬盘加快硬盘的读写效率.2. ...

  6. Mybatis中的in查询和foreach标签

    Mybatis中的foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有 item,index,collection,open,separato ...

  7. Java for LeetCode 219 Contains Duplicate II

    Given an array of integers and an integer k, find out whether there there are two distinct indices i ...

  8. ajax传值方式为数组

    js: function responseJson1(){    var array=[1001,1002];    var str="";        //获取table对象  ...

  9. AutoLayout 图解各种约束

  10. MongoDB配置文件YAML-based选项全解

    配置文件部分 MongoDB引入一个YAML-based格式的配置文件.2.4版本以前的仍然兼容. 我的mongodb配置文件: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...