zoukankan      html  css  js  c++  java
  • url参数解析 and 日期格式化

    ~function (pro) {
        //url解析
        function queryURLParameter() {
            var reg = /([^?&=#]+)=([^?&=#]+)/g,
                obj = {};
            this.replace(reg, function () {
                obj[arguments[1]] = arguments[2];
            });
            reg = /#([^?=&#]+)/;
            this.replace(reg, function () {
                obj['HASH'] = arguments[1];
            });
            return obj;
        }
        //日期格式化
        function formatDate(temp) {
            temp = temp || '{0}年{1}月{2}日 {3}时{4}分{5}秒';
            var ary = this.match(/d+/g);
            temp = temp.replace(/{(d+)}/g, function () {
                var index = arguments[1],
                    item = parseFloat(ary[index]) || 0;
                item < 10 ? item = '0' + item : null;
                return item;
            });
            return temp;
        }
    
        pro.queryURLParameter = queryURLParameter;
        pro.formatDate = formatDate;
    }(String.prototype);
    
    //用法
    var urlStr= 'http://localhost:63342/project_help/help_v2/detail.html?helpUserId=111&publishId=7777&helpType=3';
    var strObj = urlStr.queryURLParameter();
    //{helpUserId: "111", publishId: "7777", helpType: "3"}
    

      

  • 相关阅读:
    acwing793. 高精度乘法
    acwing788. 逆序对的数量
    acwing791. 高精度加法
    acwing787. 归并排序
    acwing789. 数的范围
    acwing790. 数的三次方根
    acwing786. 第k个数
    acwing792. 高精度减法
    1.9
    课程总结
  • 原文地址:https://www.cnblogs.com/geqin/p/10288642.html
Copyright © 2011-2022 走看看