var common = {}; /** * [pageMask ajax統一請求] * @return {[type]} [description] */ common.pageMask = function() { $.ajaxSetup({ beforeSend: function(xhr) ... ...
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; };