//
//if (!verification("form")) {
// return;
//}
function showloading() {
var loadinghtml = '
';
$("body").append(loadinghtml);
}
function hideloading() {
$("#loading").remove();
}
var verification = function (elem) {
this.config = {
verify: {
required: [
/[\s]+/
, '必填项不能为空'
]
, phone: [
/^1\d{10}$/
, '请输入正确的手机号'
]
, email: [
/^([a-za-z0-9_\.\-])+\@(([a-za-z0-9\-])+\.)+([a-za-z0-9]{2,4})+$/
, '邮箱格式不正确'
]
, url: [
/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/
, '链接格式不正确'
]
, number: function (value) {
if (!value || isnan(value)) return '只能填写数字'
}
, date: [
/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/
, '日期格式不正确'
]
, identity: [
/(^\d{15}$)|(^\d{17}(x|x|\d)$)/
, '请输入正确的身份证号'
]
}
};
verify = function (settings) {
var that = this;
$.extend(true, that.config.verify, settings);
return that;
};
var elem = $(elem);
var stop = true;
var verify = config.verify;
var verifyelem = elem.find('*[lay-verify]');
verifyelem.each(function (i, item) {
var othis = $(this)
, vers = othis.attr('lay-verify').split('|')
, value = othis.val();
$.each(vers, function (j) {
var thisver = vers[j]
, errortext = '' //错误提示文本
, isfn = typeof verify[thisver] === 'function';
//匹配验证规则
if (verify[thisver]) {
var istrue = isfn ? errortext = verify[thisver](value, item) : !verify[thisver][0].test(value);
errortext = errortext || verify[thisver][1];
if (thisver === 'required') {
errortext = othis.attr('lay-reqtext') || errortext;
}
//如果是必填项或者非空命中校验,则阻止提交,弹出提示
if (istrue) {
othis.focus();
alert(errortext);
return stop = false;
}
}
});
return stop;
});
return stop;
};
window.alert = function (msg, callback) {
var div = document.createelement("div");
div.innerhtml = ""
+ ""
+ "
"
+ "
"
+ "
"
+ " "
+ "
"
+ "
弹窗内容,告知当前状态、信息和解决方法,描述文字尽量控制在三行内
"
+ "
"
+ " "
+ "
"
+ "
";
document.body.appendchild(div);
var dialogs2 = document.getelementbyid("dialogs2");
dialogs2.style.display = 'block';
var dialog_msg2 = document.getelementbyid("dialog_msg2");
dialog_msg2.innerhtml = msg;
// var dialog_cancel = document.getelementbyid("dialog_cancel");
// dialog_cancel.onclick = function() {
// dialogs2.style.display = 'none';
// };
var dialog_ok2 = document.getelementbyid("dialog_ok2");
dialog_ok2.onclick = function () {
dialogs2.style.display = 'none';
//callback();
};
};