• pc端js常用方法


    var common = {};
    
        /**
         * [pageMask ajax统一请求]
         * @return {[type]} [description]
         */
        common.pageMask = function() {
            $.ajaxSetup({
                beforeSend: function(xhr) {
                    utils.mask();
                },
                complete: function(xhr, status) {
                    utils.removeMask();
                }
            });
        };
    
        /**
         * [export form表单提交 导出功能]
         * @param  {[type]} url   [description]
         * @param  {[type]} name  [description]
         * @param  {[type]} param [description]
         * @return {[type]}       [description]
         */
        common.export = function(url, name, param) {
            var form = $("<form></form>");
            form.attr('action', url);
            form.attr('method', 'post');
            for (var key in param) {
                var input = $('<input type="hidden" name="' + key + '" />');
                input.val(param[key]);
                form.append(input);
            };
            form.appendTo("body");
            form.css('display', 'none');
            form.submit();
            form.remove();
        };
    
        // 获取url中的中文值
        common.getQueryString = function(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return decodeURI(r[2]);
            }
            return '';
        };
    
           /**
             * [toThousands 数字格式处理,每三位加逗号]
             * @param  {[type]} num [description]
             * @return {[type]}     [description]
             */
            common.toThousands: function(num) {
                var result = '',
                    counter = 0;
                num = (num || 0).toString();
                for (var i = num.length - 1; i >= 0; i--) {
                    counter++;
                    result = num.charAt(i) + result;
                    if (!(counter % 3) && i != 0) {
                        result = ',' + result;
                    }
                }
                return result;
            };
    
            /**
             * [getCurrentTime 获取当前时间]
             * @return {[type]} [description]
             */
            common.getCurrentTime = function() {
                var now = new Date(),
                    year = now.getFullYear(), //获取年
                    month = now.getMonth() + 1, //获取月
                    date = now.getDate(), //获取日
                    hours = now.getHours(), //获取时
                    minutes = now.getMinutes(), //获取分
                    second = now.getSeconds(); // 获取秒
                var currentTime = {
                    year: year,
                    month: month < 10 ? '0' + month : month, //一位数补0
                    day: date < 10 ? '0' + date : date,
                    hours: hours < 10 ? '0' + hours : hours,
                    minutes: minutes < 10 ? '0' + minutes : minutes,
                    second: second < 10 ? '0' + second : second
                };
                return currentTime;
            };        
  • 相关阅读:
    Fiddler 简介
    jQuery 属性操作
    Win7的虚拟Wi-Fi
    接口与内部类
    继承(二)
    J2EE框架(Struts&Hibernate&Spring)的理解
    继承(一)
    对象与类
    控制流程
    数据类型
  • 原文地址:https://www.cnblogs.com/wpp281154/p/10443578.html
Copyright © 2020-2023  润新知