common.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Created by yuliang on 2015/5/12.
  3. */
  4. function hint(msg, duration) {
  5. duration = isNaN(duration) ? 3000 : duration;
  6. var m = document.createElement('div');
  7. m.innerHTML = msg;
  8. m.style.cssText = "width:60%; min-width:150px; background:black; opacity:0.5; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:5px; position:fixed; top:90%; left:20%; z-index:99999999; font-weight:bold;";
  9. document.body.appendChild(m);
  10. setTimeout(function () {
  11. var d = 0.5;
  12. m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
  13. m.style.opacity = '0';
  14. setTimeout(function () {
  15. document.body.removeChild(m)
  16. }, d * 1000);
  17. }, duration);
  18. }
  19. Date.prototype.format = function(format) {
  20. var date = {
  21. "M+": this.getMonth() + 1,
  22. "d+": this.getDate(),
  23. "h+": this.getHours(),
  24. "m+": this.getMinutes(),
  25. "s+": this.getSeconds(),
  26. "q+": Math.floor((this.getMonth() + 3) / 3),
  27. "S+": this.getMilliseconds()
  28. };
  29. if (/(y+)/i.test(format)) {
  30. format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  31. }
  32. for (var k in date) {
  33. if (new RegExp("(" + k + ")").test(format)) {
  34. format = format.replace(RegExp.$1, RegExp.$1.length == 1
  35. ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
  36. }
  37. }
  38. return format;
  39. }
  40. var _st = window.setTimeout;
  41. //fRef 是test函数,mDelay是时间
  42. window.setTimeout = function (fRef, mDelay) {
  43. if (typeof fRef == 'function') {
  44. var argu = Array.prototype.slice.call(arguments, 2);
  45. var f = (
  46. function () {
  47. fRef.apply(null, argu);
  48. });
  49. return _st(f, mDelay);
  50. }
  51. return _st(fRef, mDelay);
  52. }
  53. function getRequestParam(name) {
  54. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  55. var r = window.location.search.substr(1).match(reg);
  56. if (r != null) return unescape(r[2]);
  57. return null;
  58. }