Bootstrap验证控件的使用
前端HTML代码
<form id="myForm" method="post" class="form-horizontal" action="/Task/Test">
<div class="modal-body"> <div class="form-group">
<label class="col-lg-3 control-label">任务名称</label>
<div class="col-lg-5">
<input type="text" class="form-control" name="takeName" id="takeName" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">程序集名称</label>
<div class="col-lg-5">
<input type="text" class="form-control" name="dllName" id="dllName" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">类名称</label>
<div class="col-lg-5">
<input type="text" class="form-control" name="methodName" id="methodName" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">cron表达</label>
<div class="col-lg-5">
<input type="text" class="form-control" name="cron" id="cron" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">表达式说明</label>
<div class="col-lg-5">
<input type="text" class="form-control" name="cronRemark" id="cronRemark" />
</div>
</div>
<div class="form-group">
<div class="col-lg-4 col-sm-4 col-xs-4">
<div class="checkbox">
<label>
<input type="checkbox" class="colored-success" checked="checked" id="enabled">
<span class="text">启用</span>
</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">
关闭
</button>
<button type="submit" class="btn btn-primary"> 提交</button>
</div>
</form>
JS
<script>
$(document).ready(function () {
$("#myForm").bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
takeName: {
validators: {
notEmpty: {
message: '任务名称不能为空'
}
}
},
dllName: {
validators: {
notEmpty: {
message: '程序集名称不能为空'
},
//remote: {//ajax验证。server result:{"valid",true or false} 向服务发送当前input name值,获得一个json数据。例表示正确:{"valid",true}
// url: '/Task/Test3',//验证地址
// message: '用户已存在',//提示消息
// delay :3000,
// type: 'POST',//请求方式 // /**自定义提交数据,默认值提交当前input value
// * data: function(validator) {
// return {
// password: $('[name="passwordNameAttributeInYourForm"]').val(),
// whatever: $('[name="whateverNameAttributeInYourForm"]').val()
// };
// }
// */
//}, }
},
methodName: {
validators: {
notEmpty: {
message: '类名称不能为空'
}
}
},
cron: {
validators: {
notEmpty: {
message: 'cron表达不能为空'
}
}
}
},
submitHandler: function (validator, form, submitButton) {
var taskData = {};
taskData.taskName = $('#takeName').val();
taskData.dllPath = $('#dllName').val();
taskData.methodName = $('#methodName').val();
taskData.cronExpression = $('#cron').val();
taskData.remark = $('#cronRemark').val();
taskData.enabled = $('#enabled').is(':checked');
$.ajax({
type: "post",
url: "/Task/AddTask",
data:taskData,
success: function (data) {
alert(data);
$('#myForm').data('bootstrapValidator').resetForm(true);
}
});
}
}) })
</script>
该方式为AJAX提交,提交事件写在submitHandler
Bootstrap验证控件的使用的更多相关文章
- webForm中的验证控件
1.非空验证控件:RequireFieldValidator :2.数据比较验证:CompareValidator :3.数据范围验证:RangeValidator :4.正则表达式验证:Regul ...
- NET中验证控件表达式汇总
ASP.NET为开发人员提供了一整套完整的服务器控件来验证用户输入的信息是否有效.这些控件如下: 1.RequiredFieldValidator:验证一个必填字段,如果这个字段没填,那么,将不能提交 ...
- asp.net中验证控件的使用方法
用于检查是否有输入值 :RequiredFieldValidator(必须字段验证) 按设定比较两个输入 :CompareValidator(比较验证) 输入是否在指定范围 :RangeValidat ...
- 关于Web项目里的给表单验证控件添加结束时间不得小于开始时间的验证方法,日期转换和前台显示格式之间,还有JSON取日期数据格式转换成标准日期格式的问题
项目里有些不同页面间的日期显示格式是不同的, 第一个问题: 比如我用日期控件WdatePicker.js导包后只需在input标签里加上onClick="WdatePicker()" ...
- 验证控件插图扩展控件ValidatorCalloutExtender(用于扩展验证控件)和TextBoxWatermarkExtender
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptMan ...
- webform中的验证控件及两个应用技巧
一.非空验证--RequiredFiledValidator <一>属性: ErrorMessage--验证出错后的提示信息 ControlToValidate--要验证的控件的ID Di ...
- ASP.NET开发中主要的字符验证方法-JS验证、正则表达式、验证控件、后台验证
ASP.NET开发中主要的字符验证方法-JS验证.正则表达式.验证控件.后台验证 2012年03月19日 星期一 下午 8:53 在ASP.NET开发中主要的验证方法收藏 <1>使用JS验 ...
- [转].net自定义验证控件CustomValidator的使用
本文转自:http://tech.cncms.com/web/aspnet/96310.html CustomValidator验证控件,可以自定义验证函数,实现其它几个验证控件不能实现的验证规则,最 ...
- ASP.NET数据验证控件的常用的属性
一.非空验证 RequiredFieldValidator ControlToValidate 所验证的控件ID Text 出错时的提示的文本 ErrorMessage 提交给Validati ...
随机推荐
- winform之2---messagebox用法
MessageBox.Show();可谓是winform开发中用的次数最多的东东啦.先贴一张msdn的图解 msdn好像没有更新哎,只提供了这几种方法,并且参数名称和最新的有差别,但实际上messag ...
- jfinal集成spring cxf做webservice服务
链接地址:http://zhengshuo.iteye.com/blog/2154047 废话不说,直接上代码 新增cxf的plugin CXFPlugin package com.jfinal.pl ...
- 【转】java--final
1.final数据 许多程序设计语言都有自己的办法告诉编译器某个数据是“常数”.常数主要应用于下述两个方面: (1) 编译期常数,它永远不会改变 (2) 在运行期初始化的一个值,我们不希望它发生变化 ...
- STLport在vc6中的集成
STLport的下载 http://sourceforge.net/projects/stlport/ STLport的编译 * 试验环境 : win7x64sp1 + vc6sp6* 打开控制台窗口 ...
- Oracle多实例的配置方法
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME /dbhome_2) (PROGRAM ...
- 基于visual Studio2013解决C语言竞赛题之0905文件读写显示
题目
- PHP函数详细剖析之rtrim函数 By ACReaper
string rtrim ( string $str [, string $charlist ] ) 这个函数很好理解.r表示右边.trim表示修剪.即右边修剪.默认修剪字符str右边的字符.默认修剪 ...
- Cocos2d-x 3.2 大富翁游戏项目开发-第七部分 获取角色路径_3
点击下载代码 http://download.csdn.net/detail/lideguo1979/8291803 新建一个类RouteNavigation,定义getPath()方法.用来获取 ...
- PHP - 设置地址栏小图标
效果: 1/把icon图标直接放到根目录. 2/在header标签中写下: <link rel="icon" type="image/x-icon" hr ...
- HTTP 错误 500.19 – Internal Server Error web.config 文件的 system.webServer/httpErrors 节中不允许绝对物理路径“C:\inetpub\custerr”[转]
给ASP或者ASP.NET等需要配置IIS服务器的过程中,很可能会遇到以下两种错误.尤其是用Win7系统的,配置IIS7.0版本比用XP系统配置IIS5.1版本而言要复杂复杂一些.当同时需要配置ASP ...