分装的一些简单的方法

@GetQueryString(name) 解析url

function GetQueryString(name) { //取值
    var params = window.location.href.split("?")[1]
    if (params && params.match(name + "=")) {
        var str = params.split(name + '=')[1]
        try {
            var result = str.split("&")[0]
        } catch (e) {
            var result = str
        }
    } else {
        var result = null
    }
    return result
}

@parseTime(time) 解析时间戳

function parseTime(time, bool) { //解析时间戳
    var date = new Date(time)
    var year = date.getFullYear();
    var month = (date.getMonth() + 1 < 10? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    var day = date.getDate() < 10? '0' + (date.getDate()) : date.getDate();
    var h = date.getHours() < 10? '0' + date.getHours() : date.getHours();
    var m = date.getMinutes() < 10? '0' + date.getMinutes() : date.getMinutes();
    var s = date.getSeconds() < 10? '0' + date.getSeconds() : date.getSeconds();
    if (!bool) {
        return year + '/' + month + '/' + day
    } else {
        return year + '-' + month + '-' + day + ' ' + h + ':' + m + ':' + s
    }
}

@termOfValidity(startTime,endTime) 有效期

function termOfValidity(startTime, endTime, bool) { //有效期
    var timer = new Date().getTime()
    var now = 0
    if (!bool) {
        now = parseTime(timer)
        now = Number(now.replace(/\//g, ''))
    } else {
        now = parseTime(timer, true)
        now = Number(now.replace(/\-|\s|\:/g, ''))
    }
    if (now >= startTime && now <= endTime) {
        return true
    } else {
        return false
    }

}

@mosaicUrl(url,data) 拼接url

function mosaicUrl(url, data, bool) { //拼接url
    var url = url;
    if (!bool) {
        if (!/\?/g.test(url)) {
            url += "?"
            for (var i in data) {
                url += (i + "=" + data[i] + "&")
            }
            url = url.replace(/&$/, '')
        }
    } else {
        for (var i in data) {
            url += '&' + (i + "=" + data[i] + "&")
        }
        url = url.replace(/&$/, '')
    }
    return url
}

@logoutMessage(content) 提示信息

function logoutMessage(content) { //提示
    var now = new Date().getTime()
    $(".logout_model_item").remove()
    $("body").append('
' + content + '
') var timer = setTimeout(function() { $(".logout_model_" + now).remove() }, 2000) }

@loadingImage(bool) loading图

function loadingImage(bool) { //加载
    if (bool) {
        $("body").append('
' + '' + '
') } else { $(".loading_image").remove() } }

@formatNum(str) 3位添加逗号

function formatNum(str) { //3位添加逗号
    var newStr = "";
    var count = 0;
    var str = String(str)

    if (str.indexOf(".") == -1) {
        for (var i = str.length - 1; i >= 0; i--) {
            if (count % 3 == 0 && count != 0) {
                newStr = str.charAt(i) + "," + newStr;
            } else {
                newStr = str.charAt(i) + newStr;
            }
            count++;
        }
        str = newStr;
    } else {
        for (var i = str.indexOf(".") - 1; i >= 0; i--) {
            if (count % 3 == 0 && count != 0) {
                newStr = str.charAt(i) + "," + newStr;
            } else {
                newStr = str.charAt(i) + newStr; //逐个字符相接起来
            }
            count++;
        }
        str = newStr + (str + "00").substr((str + "00").indexOf("."), 3);
    }
    return str
}

@CopyObject(obj)对象复制

function CopyObject(obj){//对象复制
    var obj_buff = {}
    if(typeof(obj) != "object")
        throw new Error("参数部位对象!")

    for(var i in obj){
        obj_buff[i] = obj[i]
    }

    return obj_buff
}

@Cookie()对cookie的操作

function Cookie(){
    return {
        GetCookie: function(c_name){
            if (document.cookie.length>0){
                c_start=document.cookie.indexOf(c_name + "=")
                if (c_start!=-1){ 
                    c_start=c_start + c_name.length+1 
                    c_end=document.cookie.indexOf(";",c_start)
                    if (c_end==-1) c_end=document.cookie.length
                    return unescape(document.cookie.substring(c_start,c_end))
                } 
            }
            return ""
        },
        SetCookie:function(c_name,value,expiredays){
            var exdate=new Date()
            exdate.setDate(exdate.getDate()+expiredays)
            document.cookie=c_name+ "=" +escape(value)+
            ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
        }
    }
}

你可能感兴趣的:(分装的一些简单的方法)