this.vtip = function() {
this.xOffset = -10; // x distance from mouse
this.yOffset = 10; // y distance from mouse
$('input[required=true]').unbind().hover(
function(e) {
this.t = this.title;
this.title = '';
this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
$('body').append( '
' + this.t + '
' );
$('p#vtip #vtipArrow').attr("src", '../images/vtip_arrow.png');
$('p#vtip').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow");
},
function() {
this.title = this.t;
$("p#vtip").fadeOut("slow").remove();
}
).mousemove(
function(e) {
this.top = (e.pageY + yOffset);
this.left = (e.pageX + xOffset);
$("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
}
);
};
/*
@author f1jee
@date 2010-05-04
功能 : 元素输入检测绑定
*/
$(function(){
//vtip();
$('input[required=true]').each(function(){
$id=$(this).attr("id");
//alert($(this).attr("test1"));
$(this).bind('change',function(){
valid($(this).attr("id"));
});
$(this).bind('click',function(){
valid($(this).attr("id"));
});
$(this).bind('keyup',function(){
valid($(this).attr("id"));
});
});
});
/*
@author f1jee
@date 2010-05-04
功能 :检测输入元素数据格式
@parm:id-输入元素id
@return:检测成功返回true,否则返回false
*/
function valid(id){
value=$("#"+id).val();
title=$("#"+id).attr("title");
validType=$("#"+id).attr("validType");
if (validType=="digit") {validType="1"};
if (validType=="date") {validType="2"};
if (validType=="mail") {validType="3"};
if (validType=="zipCode") {validType="4"};
if (validType=="notNull") {validType="5"};
if (validType=="mobile") {validType="7"};
if (validType=="phone") {validType="6"};
if (validType=="string6-20") {validType="8"};
if (validType.indexOf("length")!=-1) {validType="9"};
return checkItem(title,id,validType,"1");
}
var errInfo="";
/*
@author f1jee
@date 2010-05-04
功能 :表单提交的时候执行,自动查找表单属性required=true的项目并检测
@return:检测成功返回true,否则返回false
*/
validForm = function() {
errInfo="";
var count = 0;
$('input[required=true]').each(function(){
$id=$(this).attr("id");
if (!valid($(this).attr("id"))){count++;}
});
if (count > 0) {
return false;
} else {
return true;
}
}
/*
@author f1jee
@date 2010-05-04
功能 :表单提交的时候执行,自动查找表单属性required=true的项目并检测
@parm:arg-项目json数组
[{title:"生 日",id:'birthday',format:'2',type:'text',errinfo:""}, ...]
title--------------输入项目标题
id-----------------输入项目id
format-------------输入项目格式
type---------------输入项目类型
errinfo------------错误提示的显示位置
@return:检测成功返回true,否则返回false
*/
checkForm = function(arg) {
errInfo="";
var count = 0;
//
for ( var i = 0; i < arg.length; i++) {
title=arg[i].title;
id_ = arg[i].id;
format_ = arg[i].format;
type_ = arg[i].type;
errinfo = arg[i].errinfo;
if (!checkItem(title,id_, format_, type_))
count++;
}
if (count > 0) {
return false;
} else {
return true;
}
}
/*
@author f1jee
@date 2010-05-04
功能 :检测输入元素数据格式
@parm:id-id,title-标题,dataType-输入格式,type-类型
@return:检测成功返回true,否则返回false
*/
function checkItem(title,id, dataType, type) {
type = "text";
var result = true;
value = "";
var $o = $("#" + id);
value = $("#" + id).val();
switch (Number(dataType)) {
case 1:
if (!ChkUtil.isDigit(value)) {
result = false;
error(id, $errInfo.digit);
errInfo+="";
} else {
sucess(id);
}
break;
case 2:
if (!ChkUtil.isDate(value)) {
result = false;
error(id, $errInfo.date);
errInfo+=""+title+$errInfo.date+"";
} else {
sucess(id);
}
break;
case 3:
if (!ChkUtil.isEmail(value)) {
result = false;
error(id, $errInfo.mail);
errInfo+=""+title+$errInfo.mail+"";
} else {
sucess(id);
}
break;
case 4:
if (!ChkUtil.isZipCode(value)) {
result = false;
error(id, $errInfo.zipCode);
errInfo+=""+title+$errInfo.zipCode+"";
} else {
sucess(id);
}
break;
case 5:
if (ChkUtil.isNull(value)) {
result = false;
error(id, $errInfo.notNull);
errInfo+=""+title+$errInfo.notNull+"";
} else {
sucess(id);
}
break;
case 6:
if (!ChkUtil.isMobile(value)) {
result = false;
error(id, $errInfo.mobile);
errInfo+=""+title+$errInfo.mobile+"";
} else {
sucess(id);
}
break;
case 7:
if (!ChkUtil.isPhone(value)) {
result = false;
error(id, $errInfo.phone);
errInfo+=""+title+$errInfo.phone+"";
} else {
sucess(id);
}
break;
case 8:
if (!ChkUtil.isString6_20(value)) {
result = false;
error(id, "长度为6-20");
errInfo+=""+title+":长度为6-20"+"";
} else {
sucess(id);
}
break;
case 9:
validType=$("#"+id).attr("validType");
start=validType.substring(validType.indexOf("[")+1,validType.indexOf(","));
end=validType.substring(validType.indexOf(",")+1,validType.lastIndexOf("]"));
if (!ChkUtil.isString(start,end,value)) {
result = false;
error(id, "长度为"+start+"-"+end);
errInfo+=""+title+":长度为6-20"+"";
} else {
sucess(id);
}
break;
default:
}
return result;
}
function error(id, info) {
var $o = $("#" + id);
$o.attr("class","input-err");
$o.next().remove();
$o.after($("" + info + ""));
}
function sucess(id) {
var $o = $("#" + id);
$o.attr("class","");
//alert(id);
$o.next().remove();
$o.after($(" "));
}
function showDiv(divId, o) {
if (document.getElementById(divId).style.display == 'none') {
document.getElementById(divId).style.display = 'block';
o.className = 'panel-title-fold panel-title';
} else {
document.getElementById(divId).style.display = 'none';
o.className = 'panel-title-expand panel-title';
}
}