• 自用封装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;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;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","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();\任务执行成功,关闭进度条
            }
    });
  • 相关阅读:
    Java 堆和栈 垃圾回收 2015/9/16
    多态 Java 2015/9/16
    学校项目过程中知识点 Java 2015/9/15 晚
    Python print输出不换行
    Windows 加载EXT分区
    RouterOS 安全模式
    RouterOS Openswan l2tp ipsec
    RouterOS 自动邮件备份脚本
    python chnroutes ROS版
    Kinect 2.0&Speech 11 中文语音控制
  • 原文地址:https://www.cnblogs.com/yeminglong/p/3156599.html
Copyright © 2020-2023  润新知