(@_@;)我是程序猿,我编程,我快乐,知识改变命运,技术成就梦想   oh yeah!合作VX "w6668263" 联系Email:ye583025823@126.com

自用封装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补充

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

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

 jQuery easyui loading加载等待提示......

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();\\任务执行成功,关闭进度条
        }
});

 

posted on 2013-06-26 14:56  一个草率的龙果果  阅读(383)  评论(0编辑  收藏  举报

导航