td合并

(function($) {
    
JxglUtil = {
		
    /**
     * getDbChar方法
     * 
     * 一个中文字所占数据库字符个数
     * (1)utf-8:3个字节
     * (2)其他字符集:2个字节
     */
	getDbReplaceChar:function(){
       return "***";
	},
		
    /**
     * format方法
     * usage: format("hello {0} ","king")
     */
    format:function(source, params) {            
            if (arguments.length == 1) return source;            
            if (arguments.length > 2 && params.constructor != Array) {
                params = jQuery.makeArray(arguments).slice(1);
            }
            if (params.constructor != Array) {
                params = [params];
            }
            jQuery.each(params, function(i, n) {
                source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
            });
                    
            return source;
    },
    /**
     * 判断是否在数组中存在
     * @array:js数组
     * @value:要判断是否存在的值
     */
    contains:function(array, value) { 
        for (i = 0; i < array.length; i++)
        if (array[i] == value)
            return true;
        return false;
    },
    /**
     * 去除重复数据的数组
     * @param a 数组 
     */
    uniqueDataArray:function(a) {
        var temp = new Array();
        for (var i = 0; i < a.length; i++) {
            if (!this.contains(temp, a[i])) {
                temp.length += 1;
                temp[temp.length - 1] = a[i];
            }
        }
        return temp;
    },
    /**
     * 字符串的字节长度
     * @param string 字符串
     */
    byteLength:function(string) {
        //return string.replace(/[^x00-xff]/g,"**").length;
    	return string.replace(/[^x00-xff]/g, JxglUtil.getDbReplaceChar()).length;
    },
    /**
     * 判断是否是数组
     * @param {} o
     * @return {}
     */
    isArray:function(obj) {  
        return Object.prototype.toString.call(obj) === '[object Array]';   
    },
    /**
     * td合并
     */
    tdMerge:function(prefix) {
        var array = new Array();
        
        var tds = this.format("td[class^='{0}']",prefix);
        
        jQuery(tds).each(function(i) { // 被考评对象td
            array[i] = jQuery(this).attr('class');
        });
    
        array = this.uniqueDataArray(array); // 去除重复
        
        for (var i = 0; i < array.length; i++) {
            jQuery("td[class='" + array[i] + "']").each(function(index) { // 被考评对象td
                if (index == 0) {
                    jQuery(this).attr('rowSpan', jQuery("td[class='" + array[i] + "']").length);
                } else {
                    jQuery(this).remove();
                }
            });
        }
    },
    /**
     * 清空field的值
     */
    clearFieldData:function(arrayIds) {
        if(this.isArray(arrayIds)) {
            for(var i=0;i<arrayIds.length;i++) {
                 $('#'+arrayIds[i]).val('');
            }
        } else {
            $('#'+arrayIds).val('');
        }
    },
    /**
     * 判断是否为空
     */
    isEmpty:function(fieldId,message,focus) {
        var val = jQuery.trim(jQuery('#'+fieldId).val());
        if(val==''){
            if(jQuery.trim(message)!='')alert(message);
            jQuery('#'+fieldId).focus();
//            if(focus!=undefined && focus) jQuery('#'+fieldId).focus();
            return true;
        } else {
            return false;
        }
    },
    /**
     * 判断大于最大字符
     */
    isThanMaxLenth:function(fieldId,message,maxlength) {
        var val = jQuery.trim(jQuery('#'+fieldId).val());
        if(this.byteLength(val)>maxlength){
            if(jQuery.trim(message)!='')alert(message);
            jQuery('#'+fieldId).focus();
            return true;
        } else {
            return false;
        }
    },
    
    /**
     * 绑定只能输入正负数字的text框
     * @param name: text name
     * @param maxlength: text maxlength
     */
    bindInputFloatOnlyEvent:function(name,maxlength) {
        if(maxlength==undefined)maxlength=10;
        var con = this.format("[name^='{0}']",[name]);
        jQuery(con).attr('maxlength',maxlength).bind("keypress",function() {DomUtil.inputFloatOnly();})
        .bind("paste",function() {DomUtil.pasteFloatOnly();});
    },
    
    /**
     * 绑定日期控件YYYY-MM-DD,YYYY-MM,YYYY
     */
    bindWdatePicker:function(ids,dateFormat) {
        if(this.isArray(ids)) {
            for(var i=0;i<ids.length;i++) {            	
                 this.bindWdatePickerPrivate('#'+ids[i],dateFormat);
            }
        } else {
            this.bindWdatePickerPrivate('#'+ids,dateFormat);
        }
    },
    
    /**
     * 绑定日期控件根据ID
     */
    bindWdatePickerById:function(ids,dateFormat) {
        this.bindWdatePicker(ids,dateFormat);
    },
    
    /**
     * 绑定日期控件根据名称
     */
    bindWdatePickerByName:function(names,dateFormat) {
        if(this.isArray(names)) {
            for(var i=0;i<names.length;i++) {
                 this.bindWdatePickerPrivate('[name='+names[i]+']',dateFormat);
            }
        } else {
            this.bindWdatePickerPrivate('[name='+names+']',dateFormat);
        }
    },
    
    bindWdatePickerPrivate:function(condition,dateFormat) {
    	if(undefined==dateFormat){
    		jQuery(condition).attr('readonly','readonly').addClass('Wdate').bind('click',function(){
                WdatePicker({dateFmt:'yyyy-MM-dd',skin:'whyGreen'});
            });
    	}else{
    		jQuery(condition).attr('readonly','readonly').addClass('Wdate').bind('click',function(){
                WdatePicker({dateFmt:dateFormat,skin:'whyGreen'});
            });
    	}
    },
    
    /**
     * 针对期间的初始化状态;绑定事件和赋值,和前后时间范围不能超出
     * startdateId 开始时间id
     * enddateId 结束时间id
     * startdateValue 开始时间赋值
     * enddateValue 结束时间赋值
     * dateFormat 日期格式
     * isShowClear 显示清空
     */
    initWdatePicker:function(startdateId,enddateId,startdateValue,enddateValue,dateFormat,isShowClear){
    	if(undefined==dateFormat){
    		dateFormat = 'yyyy-MM-dd';
    	}
    	if(undefined==isShowClear){
    		isShowClear = false;
    	}
        $j("#"+startdateId).click(function(){
            WdatePicker({
                maxDate: '#F{$dp.$D(\''+enddateId+'\')}',
                dateFmt: dateFormat,
                isShowClear: isShowClear,
                skin:'whyGreen'
            });
        }).addClass('Wdate').val(startdateValue).attr('readonly','readonly');
        $j("#"+enddateId).click(function(){
            WdatePicker({
                minDate: '#F{$dp.$D(\''+startdateId+'\')}',
                dateFmt: dateFormat,
                isShowClear: isShowClear,
                skin:'whyGreen'
            });
        }).addClass('Wdate').val(enddateValue).attr('readonly','readonly');
    },
    
    /**
     * 限制输入
     */
    initWdatePickerValueLimit:function(objectName, limitValue, showClear){
        jQuery('[name='+objectName+']').click(function(){
            WdatePicker({
                maxDate: limitValue,
                dateFmt: 'yyyy-MM-dd',
                isShowClear: showClear,
                skin:'whyGreen'
            });
        }).addClass('Wdate').attr('readonly','readonly');
    },
    
    /**
     * 给需要验证的元素绑定验证时用到的属性
     * 主要是caption和class属性
     * 
     * @param {Object} CheckObjArr 绑定对象的数组
     * @return 可返回绑定过的对象id数组
     */
    bindValidateAttribute:function(CheckObjArr){
        var ids = new Array();
        if(this.isArray(CheckObjArr)){
        	for(var i=0; i<CheckObjArr.length; i++){
        		jQuery("#"+CheckObjArr[i].id).attr("caption",CheckObjArr[i].caption);
        		jQuery("#"+CheckObjArr[i].id).addClass(CheckObjArr[i].clazz);
        		ids.push(CheckObjArr[i].id);
        	}
        }else{
    		jQuery("#"+CheckObjArr.id).attr("caption",CheckObjArr.caption);
    		jQuery("#"+CheckObjArr.id).addClass(CheckObjArr.clazz);
    		ids.push(CheckObjArr.id);
        }
        return ids;
    },
    
    /**
     * 给需要验证的元素使用name属性来绑定验证时用到的属性
     * 主要是caption和class属性
     * 
     * @param {Object} CheckObjArr 绑定对象的数组
     * @return 可返回绑定过的对象name数组
     */
    bindValidateAttributeByName:function(CheckObjArr){
        var names = new Array();
        if(this.isArray(CheckObjArr)){
        	for(var i=0; i<CheckObjArr.length; i++){
                jQuery("[name=" + CheckObjArr[i].name + "]").each(function(){
                    jQuery(this).attr("caption",CheckObjArr[i].caption).addClass(CheckObjArr[i].clazz);
                });
        		names.push(CheckObjArr[i].name);
        	}
        }else{
            
            jQuery("[name=" + CheckObjArr.name + "]").each(function(){
                    jQuery(this).attr("caption",CheckObjArr.caption).addClass(CheckObjArr.clazz);
            });
    		names.push(CheckObjArr.name);
        }
        return names;
    },
    
    /**
     * 转义JSon值
     * 
     * @param originalValue 原始值 
     * @return 转义后的值
     */
    transferJSonValue:function(originalValue){
           if(originalValue == null || originalValue==undefined || originalValue==""){
               return "";
           }
           return encodeURIComponent(originalValue.replace(new RegExp('(["\"])', 'g'),"\\\""));
    }
}

})(jQuery)

/**
 * 待校验的对象,用于构造进行校验属性设定的值
 * 
 * @param pId 对象的ID
 * @param pCaption 对象的名称
 * @param pClass 
 * @param pName 元素的name属性
 */
CheckObj = function(pId,pCaption,pClass,pName){
    this.id = pId;
    this.caption = pCaption;
    this.clazz = pClass;
    this.name = pName;
};

 

  js调用:        JxglUtil.tdMerge('swjg');

 

  html:<td class="swjg_11"><a name="group_names" href="javascript:doQuery()" class="list_textlink">11</a></td>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值