自用封裝javascript函數

(function(){
var JHRZ_IMG_Arr = JHRZ_IMG_Arr || {};
JHRZ_IMG_Arr.loading = ["/static/images/loading.gif", "/static/images/loading_gray.gif"];
JHRZ_IMG_Arr.normal = ["/static/images/Normal.gif"];
window["JHRZ_IMG_Arr"]=JHRZ_IMG_Arr;
})();
/**
*獲取url參數
*@name:獲取的參數名    
*/
function queryString(parameter) {
    var reg = new RegExp("(^|&)" + parameter + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
/**
*打開模態窗口
*@url 地址
*@width 寬度
*@height 高度
*/
function showDialog(url, width, height) {
    var win;
    var x = parseInt(screen.width / 2.0) - (width / 2.0);
    var y = parseInt(screen.height / 2.0) - (height / 2.0);
    if (document.all) {
        win = window.showModalDialog(url, window, "dialogWidth:" + width + "px; dialogHeight:" + height + "px; dialogLeft:" + x + "px; dialogTop:" + y + "px; status:no; directories:yes;scrollbars:no;Resizable=yes; ");
    }
    else {
        win = window.open(url, "mcePopup", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,modal=yes,width=" + width + ",height=" + height + ",resizable=no");
        eval("try { win.resizeTo(width, height); } catch(e) { }");
        win.focus();
    }
    return win;
}
/**
*加載等待提示
*@flag(true打開提示,false關閉提示)
*注意:須要將頁面html,body的style中設置margin、padding爲0,width、height爲100%;
*/
(function (flag) {
    window._loadarr=[];
    //
    var loading_div = function () { return document.getElementById("yeml_dlading") };
    //建立loading層
    var create_load_div = function () {
    if (!loading_div()) {
        var _div = document.createElement("div");
        _div.setAttribute("id", "myloading_box");
        _div.style.width = "100%";
        _div.style.height = "100%";
        _div.style.margin = "0px";
        _div.style.padding = "0px";
        var loading = "<div id='yeml_dlading' style='position:absolute;left:0;width:100%;height:100%;top:0;background:#FFFFFF;opacity:0.8;filter:alpha(opacity=90);z-index:9999999;'>";
        loading += "<div style='background:transparent url(" + JHRZ_IMG_Arr.loading[1] + ") no-repeat  scroll 10px 10px ;border:2px solid #B7CDFC;cursor:wait;position:relative;top:45%;margin:0 auto;width:200px;height:36px;line-height:36px;font-size:14px;text-indent:32px;'>";
        loading += "正在加載,請等待......</div></div>";
        _div.innerHTML = loading;
        document.body.appendChild(_div);
        window._loadarr.push(_div);
        }
    };
    //移除loading層
    var remove_load_div = function () {
        if (loading_div()) {
            document.body.removeChild(loading_div().parentNode);
        }
    };
    //
    function myLoading(flag) {
        if (flag)
            create_load_div();
        else
            remove_load_div();
    }
    window["myLoading"] = myLoading;
})();
/**將參數轉換對象
*@url   (a=1&b=2)
*return {a=1,b=2}
*/
function getQueryJson(url) {
    var ret = {}; //Object
    url.replace(/(\w+)=(\w+)/ig, function (a, b, c) { ret[b] = unescape(c); });
    return ret;
}
/**
*封裝jquery get請求ajax
*author:葉明龍
*time:2012-12-10
*/
function getAjax(url, para, fn) {
    if (typeof fn == "function") {
        if (para == undefined) {
            para = {};
        }
        $.get(url, para, function (data) {
            var obj = eval("(" + data + ")");
            fn.call(this, obj);
        })
    }
}

 2013-12-18補充css

Array.prototype.max = function(){
  return Math.max.apply({},this)
}

Array.prototype.min = function(){
  return Math.min.apply({},this)
}

 jQuery easyui loading加載等待提示......html

function ajaxLoading(){
    $("<div class=\"datagrid-mask\"></div>").css({display:"block",width:"100%",height:$(window).height()}).appendTo("body");
    $("<div class=\"datagrid-mask-msg\"></div>").html("正在處理,請稍候。。。").appendTo("body").css({display:"block",left:($(document.body).outerWidth(true) - 190) / 2,top:($(window).height() - 45) / 2});
 }
 function ajaxLoadEnd(){
     $(".datagrid-mask").remove();
     $(".datagrid-mask-msg").remove();            
}


//調用示例
$.ajax({
      type: 'POST',
      url: 'sendLettersAgain.action',
        data: {id:obj.id},
        beforeSend:ajaxLoading,\\發送請求前打開進度條
        success: function(robj){
         ajaxLoadEnd();\\任務執行成功,關閉進度條
        }
});
相關文章
相關標籤/搜索