日期:2014-05-16  浏览次数:20343 次

JAVASCRIPT常用函数集合
1、删除数组某项
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function (from, to) {
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this, rest);
};


2、当前时间

function getNow() {
	var date = new Date();
	return date.getFullYear() + "-" + (parseInt(date.getMonth()) + 1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
}


3、格式化日期
function formater(date) {
	return date.getFullYear() + "-" + (parseInt(date.getMonth()) + 1) + "-" + date.getDate();
}


4、判断是否JSON格式对象
function isJson(obj) {
	return typeof(obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length;
}