日期:2014-05-16 浏览次数:20424 次
废话少说,先上代码,以后再慢慢解释!
?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <style type="text/css"> * { margin: 0; padding: 0; } </style> <script type="text/javascript" charset="UTF-8" language="javascript"> var sinojh = { "Version" : "1.0", "Copyright" : "Copyright(c) sino-jh 2011", "Author" : "Jeff Lan", "Email" : "jefflan@live.cn", //日期格式化样式 "dateFormatStyle" : "yyyy-MM-dd hh:mm:ss", /** * 获取Url参数 * @param parameter */ "getUrlParameter" : function(parameter) { var url = location.href; var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&"); var paraObj = {}; for (var i in paraString) { var j = paraString[i]; paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length); } var returnValue = paraObj[parameter.toLowerCase()]; if (returnValue == undefined) { return ""; } else { return returnValue; } }, /** * 日期格式化 * @param date * @param format */ "dateFormat" : function(date, format) { format = format ? format : this.dateFormatStyle; var o = { "M+" : date.getMonth() + 1, //month "d+" : date.getDate(), //day "h+" : date.getHours(), //hour "m+" : date.getMinutes(), //minute "s+" : date.getSeconds(), //second "q+" : Math.floor((date.getMonth() + 3) / 3), //quarter "S" : date.getMilliseconds() //millisecond }; if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); } for ( var k in o) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; }, /** * 将日期格式的字符串转换成Date * @param dateStr * @param style */ "toDate" : function(dateStr, style) { style = style ? style : this.dateFormatStyle; var compare = { "y+" : "y", "M+" : "M", "d+" : "d", "h+" : "h", "m+" : "m", "s+" : "s" }; var result = { "y" : "", "M" : "", "d" : "", "h" : "00", "m" : "00", "s" : "00" }; var tmp = style; for ( var k in compare) { if (new RegExp("(" + k + ")").test(style)) { result[compare[k]] = dateStr.substring(tmp.indexOf(RegExp.$1), tmp.indexOf(RegExp.$1) + RegExp.$1.length); } } return new Date(result["y"], result["M"] - 1, result["d"], result["h"], result["m"], result["s"]); }, /** * 给DOM对象添加事件监听 * @param o * @param e * @param l */ "addEventListener" : function(o, e, l) { if (o.addEventListener) { o.addEventListener(e, l, false); } else if (o.attachEvent) { o.attachEvent("on" + e, function() { l(window.event); }); } }, /** * 移除DOM对象的监听事件 * @param o * @param e * @param l */ "removeEventListener" : function(o, e, l) { if (o.removeEventListener) { o.removeEventListener(e, l, false); } else if (o.detachEvent) { o.detachEvent('on' + e, function() { l(window.event); }); } }, /** * 基于数组实现的列表类 * @param capacity */ "ArrayList" : function(capacity) { capacity = capacity ? capacity : 10; var self = this; var increment = 0.75; var size = 0; var array = new Array(capacity); var amplify = function(ic) { ic = ic ? ic : Math.round(capacity * increment); var amplifyArray = new Array(ic); array = array.concat(amplifyArray); capacity = array.length; }; this.className = "sinojh.ArrayList"; this.isEmpty = function() { return size == 0; }; this.size = function() { return size; }; this.add = function(obj) { if (size >= capacity) { amplify(); } array[size] = obj; size++; }; this.addAll = function(li) { if (self.className == l