`
yuxinchao
  • 浏览: 716 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

easyui 扩展

阅读更多
from:http://uule.iteye.com/blog/2089867


EasyUI扩展方法 + jutil.js

    博客分类: jQueryEasyUi



EasyUI扩展方法:



1、我想指定textarea的行,但editor:{type:'textarea', options: {rows:'4'}}这样写不行。请问大家怎么配置才是指定行的啊?

配置Textarea不可拖动变大变小:



只能自己扩展 textarea 才能实现,配置不用修改,直接扩展就行
Js代码  收藏代码

    jQuery.extend(jQuery.fn.datagrid.defaults.editors, {   
            combotree: {   
                init: function(container, options){   
                    var editor = jQuery('<input type="text">').appendTo(container);   
                    editor.combotree(options);   
                    return editor;   
                },   
                destroy: function(target){   
                    jQuery(target).combotree('destroy');   
                },   
                getValue: function(target){   
                    var temp = jQuery(target).combotree('getValues');   
                    //alert(temp);   
                    return temp.join(',');   
                },   
                setValue: function(target, value){   
                    var temp = value.split(',');   
                    //alert(temp);   
                    jQuery(target).combotree('setValues', temp);   
                },   
                resize: function(target, width){   
                    jQuery(target).combotree('resize', width);   
                }   
            }, 
            textarea: {     
                init : function(container, options) { 
                var input = $( 
                        '<textarea class="datagrid-editable-input" style="resize:none;"></textarea>') 
                        .appendTo(container); 
                    return input; 
                }, 
                getValue : function(target) { 
                    return $(target).val(); 
                }, 
                setValue : function(target, value) { 
                    $(target).val(value); 
                }, 
                resize : function(target, width) { 
                    var input = $(target); 
                    if ($.boxModel == true) { 
                        input.width(width - (input.outerWidth() - input.width())); 
                    } else { 
                        input.width(width); 
                    } 
                } 
            }     
        });   



==========================================================================================



扩展jQuery easyui datagrid增加动态改变列编辑的类型 


Js代码  收藏代码

    $.extend($.fn.datagrid.methods, {   
        addEditor : function(jq, param) {   
            if (param instanceof Array) {   
                $.each(param, function(index, item) {   
                    var e = $(jq).datagrid('getColumnOption', item.field);   
                    e.editor = item.editor;   
                });   
            } else {   
                var e = $(jq).datagrid('getColumnOption', param.field);   
                e.editor = param.editor;   
            }   
        },   
        removeEditor : function(jq, param) {   
            if (param instanceof Array) {   
                $.each(param, function(index, item) {   
                    var e = $(jq).datagrid('getColumnOption', item);   
                    e.editor = {};   
                });   
            } else {   
                var e = $(jq).datagrid('getColumnOption', param);   
                e.editor = {};   
            }   
        }   
    });   

使用方式:   

为password字段添加一个editor 

 
Js代码  收藏代码

    $("#gridId").datagrid('addEditor', {   
                            field : 'password',   
                            editor : {   
                                type : 'validatebox',   
                                options : {   
                                    required : true   
                                }   
                            }   
                        });   

  

删除password的editor   

$("#gridid").datagrid('removeEditor', 'password');   

注:两个方法,第二个参数都可以传递数组。 



==========================================================================================



Datagrid动态设置列标题的的扩展方法

在使用datagrid时候有时候需要动态的改变一下某一列的标题。但datagrid并没有提供这一方法,一下是一个扩展的方法可以供大家使用,希望对大家能有所帮助。

扩展方法如下:
Js代码  收藏代码

    $.extend($.fn.datagrid.methods, {   
        setColumnTitle: function(jq, option){   
            if(option.field){ 
                return jq.each(function(){   
                    var $panel = $(this).datagrid("getPanel"); 
                    var $field = $('td[field='+option.field+']',$panel); 
                    if($field.length){ 
                        var $span = $("span",$field).eq(0); 
                        $span.html(option.text); 
                    } 
                }); 
            } 
            return jq;       
        }   
    }); 



调用方法如下:
Js代码  收藏代码

    $("#dt").datagrid("setColumnTitle",{field:'productid',text:'newTitle});   



==========================================================================================

其他:
Js代码  收藏代码

    $.extend($.messager.defaults,{ 
            ok:"确定", 
            cancel:"取消" 
        }); 
         
         
           
    EASYUI TAB:    
    var ctab = $('#xmlTab').tabs('getTab', 'Response XML').panel('options').tab;   
        ctab.hide();//隐藏卡片  
         
         
    解决思路:在进入行编辑状态后,获取combobox的编辑器并添加onChange事件,示例代码如下:     
    var amount = $('#tt').datagrid('getEditor', {index:editLineIndex,field:'amount'}).target;   // 个数     
    var sum = $('#tt').datagrid('getEditor', {index:editLineIndex,field:'sum'}).target; // 总数     
    amount.combobox({     
        onChange:function(id){     
            sum.val(id*100);    // 假设是text编辑类型     
        }     
    });  



baseui-all.min.js中方法使用:

其中方法如图:
Js代码  收藏代码

    var __YUIToolbarItems = { 
        getQueryItem: function() { 
            return { 
                method: "do_query", 
                iconCls: "queryAction ope-search", 
                text: "查询", 
                enable: true 
            } 
        }, 
        getAddItem: function() { 
            return { 
                method: "do_add", 
                iconCls: "addAction ope-add", 
                text: "新增", 
                enable: true 
            } 
        }, 
        getDelItem: function() { 
            return { 
                method: "do_del", 
                iconCls: "delAction ope-remove", 
                text: "删除", 
                enable: true 
            } 
        } 
        .. 
    }; 

使用:
Js代码  收藏代码

    $obj.datagrid({          
        url : _root+'/generic/query?__SERVICE_NAME=networkService',              
        idField:'id', 
        queryParams: { 
            networkId: networkId 
        }, 
        singleSelect:true, 
        showToolbar:true,            
        toolbar: [ 
              //正常方法 
              {method:'do_add',iconCls: 'ope-add',text:'新增'}, 
              //公用快捷方法 
              __YUIToolbarItems.getAddItem(), 
              __YUIToolbarItems.getSaveItem() ,        
              __YUIToolbarItems.getCancelItem()                
         ],  
    ..    

方便抽出公用按钮。



========================================

jUtil.js:
Java代码  收藏代码

    /**
     * easyui扩展/常用的方法
     * 
     * @author lk1312
     */ 
    // 定义全局对象 
    var yxui = $.extend({}, yxui); 
     
    $.parser.auto = false; 
    $(function() { 
                $.messager.progress({ 
                            text : '数据加载中....', 
                            interval : 100 
                        }); 
                $.parser.parse(window.document); 
                window.setTimeout(function() { 
                            $.messager.progress('close'); 
                            if (self != parent) { 
                                window.setTimeout(function() { 
                                            try { 
                                                parent.$.messager.progress('close'); 
                                            } catch (e) { 
                                            } 
                                        }, 500); 
                            } 
                        }, 1); 
                $.parser.auto = true; 
            }); 
    $.fn.panel.defaults.loadingMessage = '数据加载中....'; 
    $.fn.datagrid.defaults.loadMsg = '数据加载中....'; 
    // 获得根路径 rootBasePath rootPath 
    yxui.rootBasePath = function() { 
        var curWwwPath = window.document.location.href; 
        var pathName = window.document.location.pathname; 
        var pos = curWwwPath.indexOf(pathName); 
        var localhostPaht = curWwwPath.substring(0, pos); 
        var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1); 
        return (localhostPaht + projectName); 
    }; 
    yxui.rootPath = function() { 
        var pathName = window.document.location.pathname; 
        return pathName.substring(0, pathName.substr(1).indexOf('/') + 1); 
    }; 
    // 格式化字符串 formatString 
    yxui.formatString = function(str) { 
        for (var i = 0; i < arguments.length - 1; i++) { 
            str = str.replace("{" + i + "}", arguments[i + 1]); 
        } 
        return str; 
    }; 
    // 更换主题 changeTheme 
    yxui.changeTheme = function(themeName) { 
        var $yxuiTheme = $('#yxuiTheme'); 
        var url = $yxuiTheme.attr('href'); 
        var href = url.substring(0, url.indexOf('themes')) + 'themes/' + themeName + '/easyui.css'; 
        $yxuiTheme.attr('href', href); 
        var $iframe = $('iframe'); 
        if ($iframe.length > 0) { 
            for (var i = 0; i < $iframe.length; i++) { 
                var ifr = $iframe[i]; 
                $(ifr).contents().find('#easyuiTheme').attr('href', href); 
            } 
        } 
        $.cookie('yxuiTheme', themeName, { 
                    expires : 7 
                }); 
    }; 
    // 将form表单元素的值序列化成对象 
    yxui.serializeObject = function(form) { 
        var o = {}; 
        $.each(form.serializeArray(), function(index) { 
                    if (o[this['name']]) { 
                        o[this['name']] = o[this['name']] + "," + this['value']; 
                    } else { 
                        o[this['name']] = this['value']; 
                    } 
                }); 
        return o; 
    }; 
    // 操作权限控制 operId 
    yxui.operId = function(_this) { 
        $("#_operId").val($(_this).attr("_operId")); 
        $("#_resOperId").val($(_this).attr("_resOperId")); 
        $("#_resOperKey").val($(_this).attr("_resOperKey")); 
        // console.info("set->" + $("#_operId").val()); 
    }; 
    // form提交 formSubmit 
    yxui.formSubmit = function(_datagrid, _dialog, _form, _url, _callbak) { 
        var _arg = '_menuId=' + $("#_menuId").val() + '&_operId=' + $("#_operId").val() + '&_resOperId=' + $("#_resOperId").val() + '&_resOperKey=' + $("#_resOperKey").val(); 
        _url = yxui.refreshUrlLink(_url, _arg); 
        if (_form.form('validate')) { 
            _form.form('submit', { 
                        url : _url, 
                        success : function(data) { 
                            _callbak(data, _datagrid, _dialog, _form, _url); 
                        } 
                    }) 
        } 
        $("#_operId").val(''); 
    }; 
    // ajax提交 ajaxSubmit 
    yxui.ajaxSubmit = function(_datagrid, _dialog, _form, _url, _data, _callbak) { 
        // console.info("ajax get->" + $("#_operId").val()); 
        _data._operId = $("#_operId").val(); 
        _data._resOperId = $("#_resOperId").val(); 
        _data._resOperKey = $("#_resOperKey").val(); 
        $.ajax({ 
                    url : _url, 
                    type : 'post', 
                    data : _data, 
                    dataType : 'json', 
                    cache : false, 
                    success : function(response) { 
                        _callbak(response, _datagrid, _dialog, _form, _url, _data); 
                    } 
                }); 
    }; 
    // refreshUrlLink 
    yxui.refreshUrlLink = function(_url, _arg) { 
        var index = _url.indexOf('?'); 
        var length = _url.length; 
        if (index < 0) { 
            _url = _url + '?' + _arg; 
        } else if (index == length - 1) { 
            _url = _url + _arg; 
        } else { 
            _url = _url.substring(0, index + 1) + _arg + '&' + _url.substring(index + 1, length); 
        } 
        return _url; 
    }; 
    // dotoHtml 
    yxui.dotoHtml = function(tos) { 
        var returnHtml = $('#rowOperation').html(); 
        if (null != returnHtml) { 
            var maxArgsNumb = $('#_maxArgsNumb').val(); 
            if (maxArgsNumb == 0) { 
                return returnHtml; 
            } else { 
                for (var i = 0; i < maxArgsNumb; i++) { 
                    returnHtml = returnHtml.replace(new RegExp("'#arg" + i + "'", "g"), typeof(tos[i]) == 'undefined' ? 'this' : tos[i]); 
                } 
                return returnHtml; 
            } 
        } else { 
            return ""; 
        } 
    } 
    // dotoHtmlById 
    yxui.dotoHtmlById = function(id, tos) { 
        var returnHtml = $('#' + id).html(); 
        if (null != returnHtml) { 
            var maxArgsNumb = tos.length; 
            for (var i = 0; i < maxArgsNumb; i++) { 
                returnHtml = returnHtml.replace(new RegExp("'#arg" + i + "'", "g"), typeof(tos[i]) == 'undefined' ? 'this' : tos[i]); 
            } 
            return returnHtml; 
        } else { 
            return ""; 
        } 
    } 
    // dotoDiyHtml 
    yxui.dotoDiyHtml = function(returnHtml, tos, maxArgsNumb) { 
        if (null != returnHtml) { 
            if (null == maxArgsNumb || maxArgsNumb == 0) { 
                return returnHtml; 
            } else { 
                for (var i = 0; i < maxArgsNumb; i++) { 
                    returnHtml = returnHtml.replace(new RegExp("'#arg" + i + "'", "g"), typeof(tos[i]) == 'undefined' ? 'this' : tos[i]); 
                } 
                return returnHtml; 
            } 
        } else { 
            return ""; 
        } 
    } 
    // replaceAll 
    yxui.replaceAll = function(_str, _from, _to) { 
        if (null != _str) { 
            return _str.replace(new RegExp(_from, "g"), _to); 
        } else { 
            return ""; 
        } 
    } 
    // getRequestArg 
    yxui.getRequestArg = function() { 
        var _url = location.search; 
        var returnObject = {}; 
        var index = _url.indexOf("?"); 
        if (index != -1) { 
            var str = _url.substr(index + 1); 
            strs = str.split("&"); 
            for (var i = 0; i < strs.length; i++) { 
                returnObject[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); 
            } 
        } 
        return returnObject; 
    } 
    // xui.getUrlArg 
    yxui.getUrlArg = function(_url) { 
        var index = _url.indexOf("?"); 
        if (index != -1) { 
            var returnObject = {}; 
            var str = _url.substr(index + 1); 
            strs = str.split("&"); 
            for (var i = 0; i < strs.length; i++) { 
                returnObject[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); 
            } 
            return returnObject; 
        } 
        return null; 
    } 
    function getrequest() { 
        var url = location.search; // 获取url中"?"符后的字串 
        // alert(url.indexOf("?")) 
        var therequest = {}; 
        if (url.indexOf("?") != -1) { 
            var str = url.substr(1); 
            // alert(str) 
            strs = str.split("&"); 
            for (var i = 0; i < strs.length; i++) { 
                therequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); 
            } 
        } 
        return therequest; 
    } 
    /**
     * 扩展treegrid diyload treegrid查询功能
     */ 
    $.extend($.fn.treegrid.methods, { 
                diyload : function(jq, param) { 
                    return jq.each(function() { 
                                var opts = $(this).treegrid("options"); 
                                diyRequest(this, param); 
                            }); 
                } 
            }); 
    function diyRequest(jq, param) { 
        var opts = $.data(jq, "treegrid").options; 
        if (param) { 
            opts.queryParams = param; 
        } 
        if (!opts.url) { 
            return; 
        } 
        var param = $.extend({}, opts.queryParams); 
        if (opts.onBeforeLoad.call(jq, param) == false) { 
            return; 
        } 
        setTimeout(function() { 
                    doRequest(); 
                }, 0); 
        function doRequest() { 
            $.ajax({ 
                        type : opts.method, 
                        url : opts.url, 
                        data : param, 
                        dataType : "json", 
                        success : function(data) { 
                            $(jq).treegrid('loadData', data) 
                        }, 
                        error : function() { 
                            if (opts.onLoadError) { 
                                opts.onLoadError.apply(jq, arguments); 
                            } 
                        } 
                    }); 
        } 
    } 
    /**
     * 扩展tree getCheckedExt 获得选中节点+实心节点 getSolidExt 获取实心节点
     */ 
    $.extend($.fn.tree.methods, { 
                getCheckedExt : function(jq) { 
                    var checked = []; 
                    var checkbox2 = $(jq).find("span.tree-checkbox1,span.tree-checkbox2").parent(); 
                    $.each(checkbox2, function() { 
                                var thisData = { 
                                    target : this, 
                                    "checked" : true 
                                }; 
                                var node = $.extend({}, $.data(this, "tree-node"), thisData); 
                                checked.push(node); 
                            }); 
                    return checked; 
                }, 
                getSolidExt : function(jq) { 
                    var checked = []; 
                    var checkbox2 = $(jq).find("span.tree-checkbox2").parent(); 
                    $.each(checkbox2, function() { 
                                var node = $.extend({}, $.data(this, "tree-node"), { 
                                            target : this 
                                        }); 
                                checked.push(node); 
                            }); 
                    return checked; 
                } 
            }); 
    /**
     * 扩展datagrid,添加动态增加或删除Editor的方法
     */ 
    $.extend($.fn.datagrid.methods, { 
                addEditor : function(jq, param) { 
                    if (param instanceof Array) { 
                        $.each(param, function(index, item) { 
                                    var e = $(jq).datagrid('getColumnOption', item.field); 
                                    e.editor = item.editor; 
                                }); 
                    } else { 
                        var e = $(jq).datagrid('getColumnOption', param.field); 
                        e.editor = param.editor; 
                    } 
                }, 
                removeEditor : function(jq, param) { 
                    if (param instanceof Array) { 
                        $.each(param, function(index, item) { 
                                    var e = $(jq).datagrid('getColumnOption', item); 
                                    e.editor = {}; 
                                }); 
                    } else { 
                        var e = $(jq).datagrid('getColumnOption', param); 
                        e.editor = {}; 
                    } 
                } 
            }); 
    /**
     * 扩展datagrid editor 增加带复选框的下拉树/增加日期时间组件/增加多选combobox组件
     */ 
    $.extend($.fn.datagrid.defaults.editors, { 
                combocheckboxtree : { 
                    init : function(container, options) { 
                        var editor = $('<input />').appendTo(container); 
                        options.multiple = true; 
                        editor.combotree(options); 
                        return editor; 
                    }, 
                    destroy : function(target) { 
                        $(target).combotree('destroy'); 
                    }, 
                    getValue : function(target) { 
                        return $(target).combotree('getValues').join(','); 
                    }, 
                    setValue : function(target, value) { 
                        $(target).combotree('setValues', sy.getList(value)); 
                    }, 
                    resize : function(target, width) { 
                        $(target).combotree('resize', width); 
                    } 
                }, 
                datetimebox : { 
                    init : function(container, options) { 
                        var editor = $('<input />').appendTo(container); 
                        editor.datetimebox(options); 
                        return editor; 
                    }, 
                    destroy : function(target) { 
                        $(target).datetimebox('destroy'); 
                    }, 
                    getValue : function(target) { 
                        return $(target).datetimebox('getValue'); 
                    }, 
                    setValue : function(target, value) { 
                        $(target).datetimebox('setValue', value); 
                    }, 
                    resize : function(target, width) { 
                        $(target).datetimebox('resize', width); 
                    } 
                }, 
                multiplecombobox : { 
                    init : function(container, options) { 
                        var editor = $('<input />').appendTo(container); 
                        options.multiple = true; 
                        editor.combobox(options); 
                        return editor; 
                    }, 
                    destroy : function(target) { 
                        $(target).combobox('destroy'); 
                    }, 
                    getValue : function(target) { 
                        return $(target).combobox('getValues').join(','); 
                    }, 
                    setValue : function(target, value) { 
                        $(target).combobox('setValues', sy.getList(value)); 
                    }, 
                    resize : function(target, width) { 
                        $(target).combobox('resize', width); 
                    } 
                } 
            }); 
    /**
     * 扩展 datagrid/treegrid 增加表头菜单,用于显示或隐藏列,注意:冻结列不在此菜单中
     * 
     * @param e
     * @param field
     */ 
    var createGridHeaderContextMenu = function(e, field) { 
        e.preventDefault(); 
        var grid = $(this);/* grid本身 */ 
        var headerContextMenu = this.headerContextMenu;/* grid上的列头菜单对象 */ 
        if (!headerContextMenu) { 
            var tmenu = $('<div style="width:150px;"></div>').appendTo('body'); 
            var fields = grid.datagrid('getColumnFields'); 
            for (var i = 0; i < fields.length; i++) { 
                var fildOption = grid.datagrid('getColumnOption', fields[i]); 
                if (!fildOption.hidden) { 
                    $('<div iconCls="icon-ok" field="' + fields[i] + '"/>').html(fildOption.title).appendTo(tmenu); 
                } else { 
                    $('<div iconCls="icon-empty" field="' + fields[i] + '"/>').html(fildOption.title).appendTo(tmenu); 
                } 
            } 
            headerContextMenu = this.headerContextMenu = tmenu.menu({ 
                        onClick : function(item) { 
                            var field = $(item.target).attr('field'); 
                            if (item.iconCls == 'icon-ok') { 
                                grid.datagrid('hideColumn', field); 
                                $(this).menu('setIcon', { 
                                            target : item.target, 
                                            iconCls : 'icon-empty' 
                                        }); 
                            } else { 
                                grid.datagrid('showColumn', field); 
                                $(this).menu('setIcon', { 
                                            target : item.target, 
                                            iconCls : 'icon-ok' 
                                        }); 
                            } 
                        } 
                    }); 
        } 
        headerContextMenu.menu('show', { 
                    left : e.pageX, 
                    top : e.pageY 
                }); 
    }; 
    $.fn.datagrid.defaults.onHeaderContextMenu = createGridHeaderContextMenu; 
    $.fn.treegrid.defaults.onHeaderContextMenu = createGridHeaderContextMenu; 
    /**
     * 扩展 用于datagrid/treegrid/tree/combogrid/combobox/form加载数据出错时的操作
     * 
     * @param XMLHttpRequest
     */ 
    var easyuiErrorFunction = function(XMLHttpRequest) { 
        $.messager.progress('close'); 
        $.messager.alert('错误', XMLHttpRequest.responseText); 
    }; 
    $.fn.datagrid.defaults.onLoadError = easyuiErrorFunction; 
    $.fn.treegrid.defaults.onLoadError = easyuiErrorFunction; 
    $.fn.tree.defaults.onLoadError = easyuiErrorFunction; 
    $.fn.combogrid.defaults.onLoadError = easyuiErrorFunction; 
    $.fn.combobox.defaults.onLoadError = easyuiErrorFunction; 
    $.fn.form.defaults.onLoadError = easyuiErrorFunction; 
    /**
     * 防止panel/window/dialog组件超出浏览器边界
     * 
     * @param left
     * @param top
     */ 
    var easyuiPanelOnMove = function(left, top) { 
        var l = left; 
        var t = top; 
        if (l < 1) { 
            l = 1; 
        } 
        if (t < 1) { 
            t = 1; 
        } 
        var width = parseInt($(this).parent().css('width')) + 14; 
        var height = parseInt($(this).parent().css('height')) + 14; 
        var right = l + width; 
        var buttom = t + height; 
        var browserWidth = $(window).width(); 
        var browserHeight = $(window).height(); 
        if (right > browserWidth) { 
            l = browserWidth - width; 
        } 
        if (buttom > browserHeight) { 
            t = browserHeight - height; 
        } 
        $(this).parent().css({/* 修正面板位置 */ 
            left : l, 
            top : t 
        }); 
    }; 
    $.fn.dialog.defaults.onMove = easyuiPanelOnMove; 
    $.fn.window.defaults.onMove = easyuiPanelOnMove; 
    $.fn.panel.defaults.onMove = easyuiPanelOnMove; 
    /**
     * 扩展easyui的validator插件rules,支持更多类型验证
     */ 
    $.extend($.fn.validatebox.defaults.rules, { 
                minLength : { // 判断最小长度 
                    validator : function(value, param) { 
                        return value.length >= param[0]; 
                    }, 
                    message : '最少输入 {0} 个字符' 
                }, 
                length : { // 长度 
                    validator : function(value, param) { 
                        var len = $.trim(value).length; 
                        return len >= param[0] && len <= param[1]; 
                    }, 
                    message : "输入内容长度必须介于{0}和{1}之间" 
                }, 
                phone : {// 验证电话号码 
                    validator : function(value) { 
                        return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value); 
                    }, 
                    message : '格式不正确,请使用下面格式:020-88888888' 
                }, 
                mobile : {// 验证手机号码 
                    validator : function(value) { 
                        return /^(13|15|18)\d{9}$/i.test(value); 
                    }, 
                    message : '手机号码格式不正确' 
                }, 
                phoneAndMobile : {// 电话号码或手机号码 
                    validator : function(value) { 
                        return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value) || /^(13|15|18)\d{9}$/i.test(value); 
                    }, 
                    message : '电话号码或手机号码格式不正确' 
                }, 
                idcard : {// 验证身份证 
                    validator : function(value) { 
                        return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value) || /^\d{18}(\d{2}[A-Za-z0-9])?$/i.test(value); 
                    }, 
                    message : '身份证号码格式不正确' 
                }, 
                intOrFloat : {// 验证整数或小数 
                    validator : function(value) { 
                        return /^\d+(\.\d+)?$/i.test(value); 
                    }, 
                    message : '请输入数字,并确保格式正确' 
                }, 
                currency : {// 验证货币 
                    validator : function(value) { 
                        return /^\d+(\.\d+)?$/i.test(value); 
                    }, 
                    message : '货币格式不正确' 
                }, 
                qq : {// 验证QQ,从10000开始 
                    validator : function(value) { 
                        return /^[1-9]\d{4,9}$/i.test(value); 
                    }, 
                    message : 'QQ号码格式不正确' 
                }, 
                integer : {// 验证整数 
                    validator : function(value) { 
                        return /^[+]?[1-9]+\d*$/i.test(value); 
                    }, 
                    message : '请输入整数' 
                }, 
                chinese : {// 验证中文 
                    validator : function(value) { 
                        return /^[\u0391-\uFFE5]+$/i.test(value); 
                    }, 
                    message : '请输入中文' 
                }, 
                chineseAndLength : {// 验证中文及长度 
                    validator : function(value) { 
                        var len = $.trim(value).length; 
                        if (len >= param[0] && len <= param[1]) { 
                            return /^[\u0391-\uFFE5]+$/i.test(value); 
                        } 
                    }, 
                    message : '请输入中文' 
                }, 
                english : {// 验证英语 
                    validator : function(value) { 
                        return /^[A-Za-z]+$/i.test(value); 
                    }, 
                    message : '请输入英文' 
                }, 
                englishAndLength : {// 验证英语及长度 
                    validator : function(value, param) { 
                        var len = $.trim(value).length; 
                        if (len >= param[0] && len <= param[1]) { 
                            return /^[A-Za-z]+$/i.test(value); 
                        } 
                    }, 
                    message : '请输入英文' 
                }, 
                englishUpperCase : {// 验证英语大写 
                    validator : function(value) { 
                        return /^[A-Z]+$/.test(value); 
                    }, 
                    message : '请输入大写英文' 
                }, 
                unnormal : {// 验证是否包含空格和非法字符 
                    validator : function(value) { 
                        return /.+/i.test(value); 
                    }, 
                    message : '输入值不能为空和包含其他非法字符' 
                }, 
                username : {// 验证用户名 
                    validator : function(value) { 
                        return /^[a-zA-Z][a-zA-Z0-9_]{5,15}$/i.test(value); 
                    }, 
                    message : '用户名不合法(字母开头,允许6-16字节,允许字母数字下划线)' 
                }, 
                faxno : {// 验证传真 
                    validator : function(value) { 
                        return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value); 
                    }, 
                    message : '传真号码不正确' 
                }, 
                zip : {// 验证邮政编码 
                    validator : function(value) { 
                        return /^[1-9]\d{5}$/i.test(value); 
                    }, 
                    message : '邮政编码格式不正确' 
                }, 
                ip : {// 验证IP地址 
                    validator : function(value) { 
                        return /d+.d+.d+.d+/i.test(value); 
                    }, 
                    message : 'IP地址格式不正确' 
                }, 
                name : {// 验证姓名,可以是中文或英文 
                    validator : function(value) { 
                        return /^[\u0391-\uFFE5]+$/i.test(value) | /^\w+[\w\s]+\w+$/i.test(value); 
                    }, 
                    message : '请输入姓名' 
                }, 
                engOrChinese : {// 可以是中文或英文 
                    validator : function(value) { 
                        return /^[\u0391-\uFFE5]+$/i.test(value) | /^\w+[\w\s]+\w+$/i.test(value); 
                    }, 
                    message : '请输入中文' 
                }, 
                engOrChineseAndLength : {// 可以是中文或英文 
                    validator : function(value) { 
                        var len = $.trim(value).length; 
                        if (len >= param[0] && len <= param[1]) { 
                            return /^[\u0391-\uFFE5]+$/i.test(value) | /^\w+[\w\s]+\w+$/i.test(value); 
                        } 
                    }, 
                    message : '请输入中文或英文' 
                }, 
                carNo : { 
                    validator : function(value) { 
                        return /^[\u4E00-\u9FA5][\da-zA-Z]{6}$/.test(value); 
                    }, 
                    message : '车牌号码无效(例:粤B12350)' 
                }, 
                carenergin : { 
                    validator : function(value) { 
                        return /^[a-zA-Z0-9]{16}$/.test(value); 
                    }, 
                    message : '发动机型号无效(例:FG6H012345654584)' 
                }, 
                same : { 
                    validator : function(value, param) { 
                        if ($("#" + param[0]).val() != "" && value != "") { 
                            return $("#" + param[0]).val() == value; 
                        } else { 
                            return true; 
                        } 
                    }, 
                    message : '两次输入的密码不一致!' 
                } 
            }); 
    /**
     * 扩展easyui validatebox的两个方法.移除验证和还原验证
     */ 
    $.extend($.fn.validatebox.methods, { 
                remove : function(jq, newposition) { 
                    return jq.each(function() { 
                        $(this).removeClass("validatebox-text validatebox-invalid").unbind('focus.validatebox').unbind('blur.validatebox'); 
                            // remove tip 
                            // $(this).validatebox('hideTip', this); 
                        }); 
                }, 
                reduce : function(jq, newposition) { 
                    return jq.each(function() { 
                        var opt = $(this).data().validatebox.options; 
                        $(this).addClass("validatebox-text").validatebox(opt); 
                            // $(this).validatebox('validateTip', this); 
                        }); 
                }, 
                validateTip : function(jq) { 
                    jq = jq[0]; 
                    var opts = $.data(jq, "validatebox").options; 
                    var tip = $.data(jq, "validatebox").tip; 
                    var box = $(jq); 
                    var value = box.val(); 
                    function setTipMessage(msg) { 
                        $.data(jq, "validatebox").message = msg; 
                    }; 
                    var disabled = box.attr("disabled"); 
                    if (disabled == true || disabled == "true") { 
                        return true; 
                    } 
                    if (opts.required) { 
                        if (value == "") { 
                            box.addClass("validatebox-invalid"); 
                            setTipMessage(opts.missingMessage); 
                            $(jq).validatebox('showTip', jq); 
                            return false; 
                        } 
                    } 
                    if (opts.validType) { 
                        var result = /([a-zA-Z_]+)(.*)/.exec(opts.validType); 
                        var rule = opts.rules[result[1]]; 
                        if (value && rule) { 
                            var param = eval(result[2]); 
                            if (!rule["validator"](value, param)) { 
                                box.addClass("validatebox-invalid"); 
                                var message = rule["message"]; 
                                if (param) { 
                                    for (var i = 0; i < param.length; i++) { 
                                        message = message.replace(new RegExp("\\{" + i + "\\}", "g"), param[i]); 
                                    } 
                                } 
                                setTipMessage(opts.invalidMessage || message); 
                                $(jq).validatebox('showTip', jq); 
                                return false; 
                            } 
                        } 
                    } 
                    box.removeClass("validatebox-invalid"); 
                    $(jq).validatebox('hideTip', jq); 
                    return true; 
                }, 
                showTip : function(jq) { 
                    jq = jq[0]; 
                    var box = $(jq); 
                    var msg = $.data(jq, "validatebox").message 
                    var tip = $.data(jq, "validatebox").tip; 
                    if (!tip) { 
                        tip = $("<div class=\"validatebox-tip\">" + "<span class=\"validatebox-tip-content\">" + "</span>" + "<span class=\"validatebox-tip-pointer\">" + "</span>" + "</div>").appendTo("body"); 
                        $.data(jq, "validatebox").tip = tip; 
                    } 
                    tip.find(".validatebox-tip-content").html(msg); 
                    tip.css({ 
                                display : "block", 
                                left : box.offset().left + box.outerWidth(), 
                                top : box.offset().top 
                            }); 
                }, 
                hideTip : function(jq) { 
                    jq = jq[0]; 
                    var tip = $.data(jq, "validatebox").tip; 
                    if (tip) { 
                        tip.remove; 
                        $.data(jq, "validatebox").tip = null; 
                    } 
                } 
            }); 
    /**
     * 对easyui dialog 封装
     */ 
    yxui.dialog = function(options) { 
        var opts = $.extend({ 
                    modal : true, 
                    onClose : function() { 
                        $(this).dialog('destroy'); 
                    } 
                }, options); 
        return $('<div/>').dialog(opts); 
    }; 
     
    /**
     * 相同连续列合并扩展
     */ 
    $.extend($.fn.datagrid.methods, { 
                autoMergeCells : function(jq, fields) { 
                    return jq.each(function() { 
                                var target = $(this); 
                                if (!fields) { 
                                    fields = target.datagrid("getColumnFields"); 
                                } 
                                var rows = target.datagrid("getRows"); 
                                var i = 0, j = 0, temp = {}; 
                                for (i; i < rows.length; i++) { 
                                    var row = rows[i]; 
                                    j = 0; 
                                    for (j; j < fields.length; j++) { 
                                        var field = fields[j]; 
                                        var tf = temp[field]; 
                                        if (!tf) { 
                                            tf = temp[field] = {}; 
                                            tf[row[field]] = [i]; 
                                        } else { 
                                            var tfv = tf[row[field]]; 
                                            if (tfv) { 
                                                tfv.push(i); 
                                            } else { 
                                                tfv = tf[row[field]] = [i]; 
                                            } 
                                        } 
                                    } 
                                } 
                                $.each(temp, function(field, colunm) { 
                                            $.each(colunm, function() { 
                                                        var group = this; 
                                                        if (group.length > 1) { 
                                                            var before, after, megerIndex = group[0]; 
                                                            for (var i = 0; i < group.length; i++) { 
                                                                before = group[i]; 
                                                                after = group[i + 1]; 
                                                                if (after && (after - before) == 1) { 
                                                                    continue; 
                                                                } 
                                                                var rowspan = before - megerIndex + 1; 
                                                                if (rowspan > 1) { 
                                                                    target.datagrid('mergeCells', { 
                                                                                index : megerIndex, 
                                                                                field : field, 
                                                                                rowspan : rowspan 
                                                                            }); 
                                                                } 
                                                                if (after && (after - before) != 1) { 
                                                                    megerIndex = after; 
                                                                } 
                                                            } 
                                                        } 
                                                    }); 
                                        }); 
                            }); 
                } 
            }); 
    /**
     * 左到右
     */ 
    yxui.left2right = function(but) { 
        var $layout = $($(but).parents('.easyui-layout')[0]); 
        var left = $layout.find('select')[0]; 
        var rigth = $layout.find('select')[1]; 
        if ($.browser.msie) {// IE 单独处理 
            for (var i = 0; i < left.options.length; i++) { 
                var option = left.options[i]; 
                if (option.selected) { 
                    var opt = new Option(option.text, option.value); 
                    rigth.options.add(opt); 
                    left.remove(i); 
                } 
            } 
        } else { 
            $(left.options).each(function(i, n) { 
                        if (n.selected) { 
                            n.selected = false; 
                            rigth.options.add(n); 
                        } 
                    }); 
        } 
    }; 
    /**
     * 右到左
     */ 
    yxui.right2left = function(but) { 
        var $layout = $($(but).parents('.easyui-layout')[0]); 
        var left = $layout.find('select')[0]; 
        var rigth = $layout.find('select')[1]; 
        if ($.browser.msie) {// IE 单独处理 
            for (var i = 0; i < rigth.options.length; i++) { 
                var option = rigth.options[i]; 
                if (option.selected) { 
                    var opt = new Option(option.text, option.value); 
                    left.options.add(opt); 
                    rigth.remove(i); 
                } 
            } 
        } else { 
            $(rigth.options).each(function(i, n) { 
                        if (n.selected) { 
                            n.selected = false; 
                            left.options.add(n); 
                        } 
                    }); 
        } 
    } 
    /**
     * 左全到右
     */ 
    yxui.leftall2right = function(but) { 
        var $layout = $($(but).parents('.easyui-layout')[0]); 
        var left = $layout.find('select')[0]; 
        var rigth = $layout.find('select')[1]; 
        if ($.browser.msie) {// IE 单独处理 
            for (var i = 0; i < left.options.length; i++) { 
                var option = left.options[i]; 
                var opt = new Option(option.text, option.value); 
                rigth.options.add(opt); 
            } 
            $(left).empty(); 
        } else { 
            $(left.options).each(function(i, n) { 
                        rigth.options.add(n); 
                    }); 
        } 
    }; 
    /**
     * 右全到左
     */ 
    yxui.rightall2left = function(but) { 
        var $layout = $($(but).parents('.easyui-layout')[0]); 
        var left = $layout.find('select')[0]; 
        var rigth = $layout.find('select')[1]; 
        if ($.browser.msie) {// IE 单独处理 
            for (var i = 0; i < rigth.options.length; i++) { 
                var option = rigth.options[i]; 
                var opt = new Option(option.text, option.value); 
                left.options.add(opt); 
            } 
            $(rigth).empty(); 
        } else { 
            $(rigth.options).each(function(i, n) { 
                        left.options.add(n); 
                    }); 
        } 
    }; 
    /**
     * select 选择框数据采集
     * 
     * @param options
     * @return 数组
     */ 
    yxui.findSelectMultipleValue = function(options) { 
        var returnArr = [], ids = [], texts = []; 
        if ($.browser.msie) {// IE 单独处理 
            for (var i = 0; i < options.length; i++) { 
                ids.push(options[i].value); 
                texts.push(options[i].text); 
            } 
        } else { 
            $(options).each(function(i, n) { 
                        ids.push($(n).val()); 
                        texts.push($(n).html()); 
                    }); 
        } 
        returnArr.push(ids); 
        returnArr.push(texts); 
        return returnArr; 
    } 
分享到:
评论

相关推荐

    easyui 扩展 带单位输入框

    本文将深入探讨如何在EasyUI中扩展一个带有单位输入框的自定义插件,这在处理需要指定单位(如长度、重量等)的数据输入场景时非常有用。 ### 标题解析:“easyui 扩展 带单位输入框” 标题明确了本文的主题是关于...

    easyui扩展版本的插件

    在"easyui扩展版本的插件"中,我们看到的是对原生EasyUI组件的进一步增强和定制,以满足更具体的需求。 1. **日期组件扩展**:原生的EasyUI日期选择器通常提供了基本的日历功能,但扩展版本可能包含了更多的自定义...

    EasyUI扩展图标样式

    "EasyUI 扩展图标样式" 是一种针对 EasyUI 原有图标集的增强,旨在提供更多的图标选项,以适应更多样化的界面设计。这个扩展仅仅关注图标本身,不涉及其他的界面风格,确保了与现有 EasyUI 设计的兼容性。开发者可以...

    EasyUI 扩展ICON图标

    "EasyUI 扩展ICON图标" 提供了一个解决方案,它增加了1775个额外的图标,大大丰富了EasyUI的图标库。这些图标可能是矢量图形,可以在不同分辨率和尺寸下保持清晰,同时涵盖了各种常见的功能类别,如导航、操作、状态...

    jquery easyui扩展js验证

    easyui扩展的js验证,是对easyUI没有的验证做的补充扩展,好用方便

    Easyui的扩展图标

    10. **文档和示例**:使用Easyui扩展图标时,应参考其官方文档或提供的示例代码,以便更好地理解和应用这些图标。 总之,Easyui的扩展图标为开发者提供了更多的设计元素,使得构建用户界面更加灵活,同时也需要注意...

    EasyUI扩展方法 + jutil.js

    从描述中的“总包”来看,这个压缩包可能包含了一系列与EasyUI扩展和jutil.js相关的资源,如CSS样式文件、JavaScript脚本、示例代码或者文档,供开发者参考和使用。通过提供的博文链接(已省略),可以获取更多关于...

    EasyUI 扩展小图标Icon带CSS样式

    "EasyUI 扩展小图标Icon带CSS样式" 是为了应对EasyUI内置图标不足和美观度不高的问题而创建的资源包。这个扩展包包含了一套更全面、更美观的图标库,适用于各种项目需求,可以直接整合到基于EasyUI的项目中使用,极...

    JQuery easyUI扩展验证机制的正则表达式

    ### JQuery easyUI扩展验证机制的正则表达式详解 #### 一、概述 在Web开发过程中,表单数据的有效性和准确性对于用户体验至关重要。为了确保用户输入的数据符合预期的格式,前端验证成为了一项必不可少的任务。...

    jQuery EasyUI 扩展(tip和form)

    在"jQuery EasyUI 扩展(tip和form)"这个主题中,我们将深入探讨如何利用 EasyUI 的扩展功能来优化提示(tip)和表单(form)的交互体验。 首先,让我们谈谈“Tip”。在 Web 开发中,提示信息通常用于向用户提供即时...

    jquery easyui 扩展图标样式下载(514个)

    针对这种情况,标题提到的 "jquery easyui 扩展图标样式下载(514个)" 是一个资源包,为EasyUI用户提供了额外的514个图标,以扩充其图标库。 这个资源包包含两部分主要内容:图标图片文件和样式文件。图标图片文件...

    easyui 扩展layout的方法,支持动态添加删除块

    ### easyUI扩展Layout方法以支持动态添加与删除区块 #### 概述 easyUI是一款基于jQuery的用户界面库,它提供了丰富的UI组件和强大的布局管理功能。本文将详细介绍如何通过扩展easyUI的`layout`方法来实现动态添加...

    千余个网站实用按钮图标附带easyui扩展图标样式文件

    本文将深入探讨“千余个网站实用按钮图标附带easyui扩展图标样式文件”这个主题,包括其中包含的资源以及如何在项目中有效地使用它们。 首先,我们要了解EasyUI。EasyUI是一个基于JavaScript和jQuery的轻量级框架,...

    easyUI扩展图标

    EasyUI扩展图标是一套丰富的图形资源,专为增强和扩展EasyUI框架的视觉表现而设计。EasyUI是一款基于JavaScript和CSS的轻量级前端开发框架,它简化了网页用户界面的构建过程,提供了诸如对话框、菜单、表格、布局等...

    EasyUi图标扩展样式大全(1700个)

    标题提到的“EasyUi图标扩展样式大全(1700个)”是一个专门针对EasyUi的图标库增强方案,旨在解决EasyUI默认图标样式不足和美观度不高的问题。 这个扩展样式大全包含了1700个图标,大大增加了EasyUI在设计界面时的...

    EasyUi图标扩展样式.7z

    EasyUI图标扩展样式是针对EasyUI框架的一种增强,旨在提供更多的视觉元素,以满足开发者在构建用户界面时对个性化和多样性的需求。EasyUI是一个基于jQuery的轻量级且易于使用的前端开发框架,它提供了丰富的组件,如...

    easyui扩展图标

    easyui扩展图标

    Easyui扩展datagrid-dnd.js,实现拖动grd的必要文件

    Easyui的扩展datagrid-dnd.js,实现拖动datagrid行到其他数据表格的必要文件

Global site tag (gtag.js) - Google Analytics