$.extend($, { 'alert': function(options) { if (Object.prototype.toString.call(options) == '[object String]') { options = { 'content': options }; } var options = $.extend({ 'content' : '', 'title' : '提示', 'init' : function(e, dom){}, 'callback' : function(e, dom){}, 'size' : '', 'bgcolor' : '', 'btntext' : '确认', 'btnbg' : 'btn-primary', 'btncancel' : false }, options); var id = 'msgbox_id_' + Math.floor(Math.random() * 100000000); var btncancel = options.btncancel ? '' : ''; var html = ``; var jq = $(html); $(document.body).append(jq); $('.btn-primary', jq).click(function(e){ if (options.callback && options.callback(jq) !== false) { jq.modal('hide'); } }); jq.on('show.bs.modal', function(e){ if (options.init) { options.init(jq); } }); jq.on('hidden.bs.modal', function(e){ $(this).remove(); }); jq.modal('show'); } }); function time2str(timestamp, cnFormat) { var obj = new Date(timestamp * 1000); if(cnFormat) { var Y = obj.getFullYear(), m = obj.getMonth() + 1, d = obj.getDate(), H = obj.getHours(), i = obj.getMinutes(), s = obj.getSeconds(); return Y + '-' + (m < 10 ? '0'+m : m) + '-' + (d < 10 ? '0'+d : d) + ' ' + (H < 10 ? '0'+H : H) + ':' + (i < 10 ? '0'+i : i) + ':' + (s < 10 ? '0'+s : s); } else { return obj.toLocaleString(); } } function size2str(size) { if(size < 1024) { return size + '字节'; } else if(size < 1024*1024) { return numberRound(size / 1024, 2) + 'K'; } else if(size < 1024*1024*1024) { return numberRound(size / 1024 / 1024, 2) + 'M'; } else { return numberRound(size / 1024 / 1024 / 1024, 2) + 'G'; } } function numberFormat(n, len) { n = parseInt(n); len = len == 4 ? 4 : 3; if(n == NaN) { return 0; } var sign = n < 0 ? '-' : ''; var str = '' + Math.abs(n), ret = ''; var mod = str.length % len; if(mod > 0) { ret += str.substr(0, mod) + ','; } for(var i=mod; i pages) { return; } var html = ''; var jq = $('#' + options.id); jq.html(html); $('a', jq).click(function(){ options.callback($(this).attr('data-value')); return false; }); }