js expand

1 、Date

  

  Date.prototype.setDate1 = function (i) {
            this.setDate(i);
            return this;
        }
        Date.prototype.Format = function (fmt) { //author: meizz   
            var o = {
                "M+": this.getMonth() + 1,                 //月份   
                "d+": this.getDate(),                    //日   
                "h+": this.getHours(),                   //小时   
                "m+": this.getMinutes(),                 //分   
                "s+": this.getSeconds(),                 //秒   
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
                "S": this.getMilliseconds()             //毫秒   
            };
            if (/(y+)/.test(fmt))
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt))
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }

2、JS版StringBuilder

  

        function StringBuilder() {
            this._str = '';
            this._data = Array("");
            this.length = function () {
                return this.toString().length;
            };
            this.append = function () {
                for (var i = 0; i < arguments.length; i++) {
                    this._data.push(arguments[i]);
                }
            }
            this.toString = function () {
                this._str += this._data.join("");
                this._data = new Array("");
                return this._str;
            }
            this.remove = function (start, end) {
                this._str += this._data.join("");
                this._data = new Array("");
                if (!start && !end) return this._str;
                if (start && !end) {
                    this._str = this._str.substr(0, start)
                    return this._str
                };
                if (start && end) {
                    this._str = (this._str.substr(0, start) + this._str.substr(end, this._str.length))
                    return this._str;
                }
            }
        }

3、ajaxHelper

        function AjaxHelper(async, contentType) {
            this.async = (async == null || async == undefined) ? true : async;
            this.contentType = (contentType == null || contentType == undefined) ? "application/json" : contentType;
            this.AjaxPost = function (url, data, successCallBack, errorCallBack) {
                $.ajax({
                    async: this.async,
                    type: 'post',
                    url: url,
                    contentType: this.contentType,
                    datatype: "json",
                    data: data,
                    success: function (result) {
                        if (successCallBack) {
                            successCallBack(result);
                        }
                    },
                    error: function (error) {
                        if (errorCallBack) {
                            errorCallBack(error);
                        }
                    }
                });
            }
            this.AjaxGet = function (url, successCallBack, errorCallBack) {
                $.ajax({
                    async: this.async,
                    type: 'get',
                    url: url,
                    datatype: "json",
                    success: function (result) {
                        if (successCallBack) {
                            successCallBack(result);
                        }
                    },
                    error: function (error) {
                        if (errorCallBack) {
                            errorCallBack(error);
                        }
                    }
                });
            }
        }  //ajax

4、js dom

  (1)dom.offsetTop和dom.offsetLeft  -->获取dom元素的相对与有absolute和relative或body的top和left位置。

  (2)dom.offsetParent  -->获取父元素并且要有absolute和relative或body等的dom元素。

posted @ 2016-04-26 17:13  立于群  阅读(410)  评论(0)    收藏  举报