`

javascript校验实例一

 
阅读更多

 

//公共类型;
validTypeArray = new Array();

/**
 * 给窗体绑定resize事件;
 */
function bindResizeEvent(){
	//移除窗体改变大小时触发的事件;
	jQuery(window).unbind("resize");
	
	//窗体改变大小时触发resize事件;
	jQuery(window).resize(function(){
		submitCommonJS();
	});
}

/**
 * 移除图标方法;
 * @param txtObj
 */
function removeImage(txtObj){
	//移除图标;
	txtObj.parent().children("#successDivID").remove();
	txtObj.parent().children("#errorDivID").remove();
	txtObj.parent().children("#tipMsgDivID").remove();
	txtObj.parent().children("#errorMsgDivId").remove();
	txtObj.parent().children("#pointerDivID").remove();
}

//设置鼠标移动到图标上面移除事件;
jQuery(document).ready(function(){
	//给第一个文本框获取焦点;
	jQuery("input[type='text']").first().focus();
	jQuery("input[type='text']").each(function(i){
		//移出绑定事件;
		jQuery(this).unbind("mouseover");
		//绑定事件;
		jQuery(this).bind("mouseover",function(){
			jQuery(this).parent().children("#tipMsgDivID").hide();
		});
	});
});

//检验对象;
CheckOut = function(){
	//字段数组;
	var fieldArray = new Array();
	//添加addField对象;
	this.addField = function(options){
		// 以ID的方式获取文本框
		this.id = options.id == undefined ? null:options.id;
		// 以名称的方式获取文本框
		this.name = options.name == undefined ? null:options.name;
		// 以类样式的方式获取文本框
		this.className = options.className == undefined ? null:options.className;
		// 文本框是否必须
		this.isRequired = options.isRequired == undefined ? false:options.isRequired;
		// 校验类型
		this.validType = options.validType == undefined ? null:options.validType;
		// 文本框为空时的提示信息
		this.emptyMsg = options.emptyMsg == undefined ? $("#emptyMsg").val():options.emptyMsg;
		// 文本框校验失败时的提示信息
		this.invalidMsg = options.invalidMsg == undefined ? null:options.invalidMsg;
		// 文本框的默认值
		this.defaultValue = options.defaultValue == undefined ? null:options.defaultValue;
		//往数组中添加addField对象;
		fieldArray.push(options);
	};
	
	//返回数组;
	this.getFieldArray=function(){
		return fieldArray;
	};
};

/**
 * 替换国际化;
 * @param i18nMsgInfo
 * @param param1
 * @param param2
 * @returns
 */
CheckOut.replace = function (i18nMsgInfo,param1,param2){
	if(i18nMsgInfo!=null && i18nMsgInfo!=""){
		i18nMsgInfo = i18nMsgInfo.replace("{0}",param1);
		i18nMsgInfo = i18nMsgInfo.replace("{1}",param2);
	}
	return i18nMsgInfo;
};
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics