重写jquery serialize 方法

 

/**取表单中的对象
    *attrName:为元素的的属性名称不设置则默认为name
    */
    $.fn.serialize = function (attrName) {
        var ret = {};
        if (!attrName) {attrName = "name";}

        $(this).find("*[" + attrName + "]").each(function (i, o) {
            var thisObj = $(o);
            var attrValue = thisObj.attr(attrName);

            var curValue = null;
            if (thisObj.is(":input")) {
                if (thisObj.is(".easyui-textbox"))
                    curValue=thisObj.textbox("getValue");
                else if (thisObj.is('.easyui-combobox'))
                    curValue=thisObj.combobox("getValue");
                else
                    curValue =thisObj.val();
            }
            else {
                curValue =thisObj.text();
            }
            ret[attrValue.split(".")[0]] = curValue;
        });

        return ret;
    };

 

posted @ 2017-06-28 17:26  三瑞  阅读(335)  评论(0编辑  收藏  举报