function dateGetter(name, size, offset, trim) {
offset = offset || 0;
return function (date) {
var value = date['get' + name]();
if (offset > 0 || value > -offset)
value += offset;
if (value === 0 && offset == -12) value = 12;
return padNumber(value, size, trim);
};
};
function padNumber(num, digits, trim) {
var neg = '';
if (num < 0) {
neg = '-';
num = -num;
}
num = '' + num;
while (num.length < digits) num = '0' + num;
if (trim)
num = num.substr(num.length - digits);
return neg + num;
};
function dateStrGetter(name, shortForm) {
return function(date, formats) {
var value = date['get' + name]();
var get = (shortForm ? ('SHORT' + name) : name).toUpperCase(); return formats[get][value];
};
};
window.IGrow = {};
var Utilities = {
getParameterByName: function (name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
},
findElement: function (arr, propName, propValue) {
for (var i = 0; i < arr.length; i++)
if (arr[i][propName] == propValue)
return arr[i];
},
findWithAttr: function (array, attr, value) {
for (var i = 0; i < array.length; i += 1) {
if (array[i][attr] === value) {
return i;
}
}
},
jsonObjToBase64: function (json) {
return btoa(encodeURIComponent(JSON.stringify(json)));
},
base64TojsonObj: function (base64) {
return JSON.parse(decodeURIComponent(atob(base64)));
},
pageJump: function (url) {
location.href = url;
},
log: function () {
for(key in arguments){
console.log(JSON.parse(JSON.stringify(arguments[key])));
}
},
copy: function (source) {
var result = source instanceof Array ? [] : {};
for (var key in source) {
result[key] = typeof source[key] === 'object' ? this.copy(source[key]) : source[key];
}
return result;
},
params: function () {
var url = window.location.search;
if (url.indexOf("?") != -1) {
var str = url.substr(1),
strs = str.split("&"),
key = new Array(strs.length),
value = new Array(strs.length),
params = {};
for (var i = 0; i < strs.length; i++) {
key[i] = strs[i].split("=")[0]
value[i] = unescape(strs[i].split("=")[1]);
params[key[i]] = value[i]
}
return params;
}
},
getTime: function (date, format) {
var text = '',
parts = [],
fn, match;
while (format) {
match = /((?:[^yMdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z|G+|w+))(.*)/.exec(format);
if (match) {
parts = parts.concat([].slice.call(match, 1));
format = parts.pop();
} else {
parts.push(format);
format = null;
}
}
parts.forEach(function(value) {
fn = DATE_FORMATS[value];
text += fn ? fn(new Date(date))
: value.replace(/(^'|'$)/g, '').replace(/''/g, "'");
});
return text;
},
tip: function (msg,time) {
var html = '<div class="weui_dialog_alert" id="tip">' +
'<div class="weui_mask"></div>' +
'<div class="weui_dialog">' +
'<div class="weui_dialog_hd"><strong class="weui_dialog_title">提示</strong></div>' +
'<div class="weui_dialog_bd">' + msg + '</div>' +
'<div class="weui_dialog_ft">', time = time || 2000;
if ($('#tip').length) {
$('#tip').find('.weui_dialog_bd').html(msg);
$('#tip').show();
} else {
$('body').append(html);
}
$('#tip').off().click(function(){
$(this).hide();
});
setTimeout(function () {
$('#tip').hide();
}, time);
},
extend: function () {
var _extend,
_isObject,
arr = arguments,
result = {},
i; _isObject = function (o) {
return Object.prototype.toString.call(o) === '[object Object]';
}; _extend = function self(destination, source) {
var property;
for (property in destination) {
if (destination.hasOwnProperty(property)) { // 若destination[property]和sourc[property]都是对象,则递归
if (_isObject(destination[property]) && _isObject(source[property])) {
self(destination[property], source[property]);
}
; // 若sourc[property]已存在,则跳过
if (source.hasOwnProperty(property)) {
continue;
} else {
source[property] = destination[property];
}
}
}
}; if (!arr.length) return {}; for (i = arr.length - 1; i >= 0; i--) {
if (_isObject(arr[i])) {
_extend(arr[i], result);
}
} arr[0] = result; return result;
},
forEach: function (obj, iterator, context) {
var key, length;
if (obj) {
if (typeof obj == 'function') {
for (key in obj) {
// Need to check if hasOwnProperty exists,
// as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function
if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) {
iterator.call(context, obj[key], key, obj);
}
}
} else if ($.isArray(obj)) {
var isPrimitive = typeof obj !== 'object';
for (key = 0, length = obj.length; key < length; key++) {
if (isPrimitive || key in obj) {
iterator.call(context, obj[key], key, obj);
}
}
} else if (obj.forEach && obj.forEach !== Utilities.forEach) {
obj.forEach(iterator, context, obj);
} else {
for (key in obj) {
if (obj.hasOwnProperty(key)) {
iterator.call(context, obj[key], key, obj);
}
}
}
}
return obj;
}
    };

    Utilities.routeParams = Utilities.params();

常用js方法,extend合并对象,copy深拷贝对象,tip提示信息框,getTime返回自定义格式时间,params获取浏览器地址参数,log打印相关变量,forEach循环对象或数组

常用js方法的更多相关文章

  1. 常用js方法整理common.js

    项目中常用js方法整理成了common.js var h = {}; h.get = function (url, data, ok, error) { $.ajax({ url: url, data ...

  2. 项目中常用js方法整理common.js

    抽空把项目中常用js方法整理成了common.js,都是网上搜集而来的,大家一起分享吧. var h = {}; h.get = function (url, data, ok, error) { $ ...

  3. 常用js方法封装

    常用js方法封装 var myJs = { /* * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值是格式化的字符串日期 */ getDates: fun ...

  4. 常用js方法整理(个人)

    开头总要有点废话 今天想了下,还是分享下自己平时积累的一些实用性较高的js方法,供大家指点和评价.本想分篇介绍,发现有点画蛇添足.整理了下也没多少拿得出手的方法,自然有一些是网上看到的个人觉得很有实用 ...

  5. Dynamics CRM 常用 JS 方法集合

    JS部分 拿到字段的值 var value= Xrm.Page.getAttribute("attributename").getValue(); Xrm.Page.getAttr ...

  6. 常用JS方法整理

    目录: 截取指定字节数的字符串 判断是否微信 获取时间格式的几个举例 获取字符串字节长度 对象克隆.深拷贝 组织结构代码证验证 身份证号验证 js正则为url添加http标识 URL有效性校验方法 自 ...

  7. 前端开发常用 JS 方法

    1,获取文件本地url,在上传之前预览 /** * 获取图片嗯滴url,在上传之前预览 * @param file 选择的图片文件 * @returns {*} url */ getFileLocat ...

  8. 项目常用JS方法封装--奋斗的IT青年(微信公众号)

                                                                                                        ...

  9. 常用js方法函数

    常用方法函数 1.深复制 // 1.深复制 function deepCopy(source) { var result = {}; for (var key in source) { result[ ...

随机推荐

  1. centos 安装pptp

    1. 安装依赖 ppp yum -y install ppp 2. 编译安装pptpd wget http://jaist.dl.sourceforge.net/project/poptop/pptp ...

  2. 南非的5DT数据手套使用说明

    数据手套-5 Ultra/数据手套-14 Ultra 5DT 数据手套-Ultra数据手套的设计目的是为了满足现代动作捕捉和动画制作等专业人士的严格要求.它提供了舒适,易于使用,小型要素和多种应用的驱 ...

  3. CallBack实践。

    第一:它的应用场景是什么? if you call me ,i will call back.目前我接触到两种需要回调的需求 1.系统管理平台登录,登录所需要的人员和部门数据都是在另一个基础信息系统中 ...

  4. sed

    命令行格式为:         sed [-nefri]  ‘command’  输入文本/文件 常用选项:        -n∶取消默认的输出,使用安静(silent)模式.在一般 sed 的用法中 ...

  5. 利用selector设置ImageButton不同状态下的背景图片

    1.自定义MyButton类 public class MyButton extends Button { //This constructormust be public MyButton(Cont ...

  6. EditPlus 3.7 中文版已经发布

    新一版的 EditPlus 已经在昨天发布了!新版本增加了一个 64位版程序.大家可以到官方网站下载哦. 我同步更新翻译了 32位版应用程序.请点击页面左上角的链接下载.

  7. C#如何反射出委托的签名,如何使用反射调用委托

    本文阐述C#中如何反射出委托的签名,假如我们有委托FooDelegate定义如下 delegate double FooDelegate (string param, bool condition); ...

  8. Global.asax文件说明

    Global.asax是我们的底层文件,第一次的IIS请求都会先去执行它里面的文件,所以学会它里面的函数是非常有必要的.而且我们总是忽略这里的知识点,总觉得这是不必须的,其实我们错了,这里才是程序的根 ...

  9. next([expr]) 取得一个包含匹配的元素集合中每一个元素紧邻的后面同辈元素的元素集合。

    描述: 找到每个段落的后面紧邻的同辈元素. HTML 代码: <p>Hello</p><p>Hello Again</p><div>< ...

  10. Linux下面配置文件~/.bash_profile

    ~/.的意义是什么? ~ 代表你的/home/用户名目录 假设你的用户名是x,那么~/就是/home/x/ . 是代表此目录本身,但是一般可以不写 所以cd ~/. 和cd ~ 和cd ~/效果是一样 ...