封装一个form表单, 让它可以使用验证, 可以ajax方式提交数据, 支持CTRL+S提交数据。
§ 原型:
<jQuery> $(form).ajaxForm(
jsonok, // <function>(json) 提交后回调函数
infoHandler, // <function>(element, msg, type, event) 验证提示处理函数
// or jQuery | DOMElement
beforeSubmit // <function>(form)
// 数据准备好了, 准备提交, 这时候做些事情, 比较修改下序列化后数据
);
§ 举例:
$(form).ajaxForm(function(json){
if (json.state) {
cmstop.ok(json.info);
setTimeout(function(){
location = '?otherurl';
}, 2000);
} else {
cmstop.error(json.error);
}
}, function(element, msg, type, event){
// element 提示的元素input, textarea, select
// msg 提示的信息
// type 提示的类型 vali_error, vali_pass, vali_verifing
// event $.event处理过的event
if (msg) {
cmstop.tips(msg, type == 'vali_error' ? 'error' : ( type == 'vali_ok' ? 'ok' : 'warnning'));
element.addClass(type);
}
}, function(form){
// 将忽略的数据disabled
form.find('input.ignored').attr('disabled', true);
return false; // 表示不提交
})