码迷,mamicode.com
首页 > Web开发 > 详细

常用js函数封装

时间:2016-08-19 12:59:17      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

// 获取网址的get参数
var GET = function(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return (r[2]);
  return null;
}

 

// 13位时间戳转日期
var getLocalTime = function(nS) {
  //return new Date(parseInt(nS)).toLocaleString().replace(/:\d{1,2}$/,‘ ‘);
  var date = new Date(nS);
  var Y = date.getFullYear() + ‘/‘;
  var M = (date.getMonth() + 1 < 10 ? ‘0‘ + (date.getMonth() + 1) : date.getMonth() + 1) + ‘/‘;
  var D = (date.getDate() < 10 ? ‘0‘ + (date.getDate()) : date.getDate()) + ‘ ‘;
  var h = date.getHours() + ‘:‘;
  var m = (date.getMinutes() < 10 ? ‘0‘ + (date.getMinutes()) : date.getMinutes()) + ‘ ‘;
  //var s = date.getSeconds();
  return Y + M + D + h + m;
}

 

// 数组对象排序  data.sort(keysrt("firstWord"));
var keysrt = function(propertyName) {
  return function(object1, object2) {
    var value1 = object1[propertyName];
    var value2 = object2[propertyName];
    if (value2 < value1) {
      return 1;
    } else if (value2 > value1) {
      return -1;
    } else {
      return 0;
    }
  }
}

 

常用js函数封装

标签:

原文地址:http://www.cnblogs.com/woodk/p/5787154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!