分类 javascripts 下的文章

/*===================下载文件
 * options:{
 * url:'',  //下载地址
 * data:{name:value}, //要发送的数据
 * method:'post'
 * }
 */
var DownLoadFile = function (options) {
    var config = $.extend(true, { method: 'post' }, options);
    var $iframe = $('<iframe id="down-file-iframe" />');
    var $form = $('<form target="down-file-iframe" method="' + config.method + '" />');
    $form.attr('action', config.url);
    for (var key in config.data) {
        $form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" />');
    }
    $iframe.append($form);
    $(document.body).append($iframe);
    $form[0].submit();
    $iframe.remove();
}

if (!Array.prototype.indexOf){
  Array.prototype.indexOf = function(elt /*, from*/){
    var len = this.length >>> 0;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++){
      if (from in this && this[from] === elt)
        return from;
    }
    return -1;
  };
}

window._console = window.console;//将原始console对象缓存  
window.console = (function (orgConsole) {  
    return {//构造的新console对象  
        log: getConsoleFn("log"),  
        debug: getConsoleFn("debug"),  
        info: getConsoleFn("info"),  
        warn: getConsoleFn("warn"),  
        exception: getConsoleFn("exception"),  
        assert: getConsoleFn("assert"),  
        dir: getConsoleFn("dir"),  
        dirxml: getConsoleFn("dirxml"),  
        trace: getConsoleFn("trace"),  
        group: getConsoleFn("group"),  
        groupCollapsed: getConsoleFn("groupCollapsed"),  
        groupEnd: getConsoleFn("groupEnd"),  
        profile: getConsoleFn("profile"),  
        profileEnd: getConsoleFn("profileEnd"),  
        count: getConsoleFn("count"),  
        clear: getConsoleFn("clear"),  
        time: getConsoleFn("time"),  
        timeEnd: getConsoleFn("timeEnd"),  
        timeStamp: getConsoleFn("timeStamp"),  
        table: getConsoleFn("table"),  
        error: getConsoleFn("error"),  
        memory: getConsoleFn("memory"),  
        markTimeline: getConsoleFn("markTimeline"),  
        timeline: getConsoleFn("timeline"),  
        timelineEnd: getConsoleFn("timelineEnd")  
    };  
    function getConsoleFn(name) {  
        return function actionConsole() {  
            if (typeof (orgConsole) !== "object") return;  
            if (typeof (orgConsole[name]) !== "function") return;//判断原始console对象中是否含有此方法,若没有则直接返回  
            return orgConsole[name].apply(orgConsole, Array.prototype.slice.call(arguments));//调用原始函数  
        };  
    }  
}(window._console));