组件的使用demo object.js if (typeof window.ceopen == "undefined") { window.ceopen = {}; } if (typeof window.ceopen.object == "undefined") { window.ceopen.object = {}; } (function(package){ jQuery.extend(package, { /** * @description 创建类 * @function * @param {Function} [superClass=null] 所创建类的父类 * @param {Map} newMethod 要创建类的方法和属性 * @return {Function} 创建的新类 * .[_super] {Object} 新类的父类原型(prototype) */ createClass : function(superClass, newMethod){ var parent = typeof superClass == "function" ? jQuery.extend({}, superClass.prototype) : superClass; var newClass = function(){ if(jQuery.isFunction(this.init)){ this.init.apply(this, arguments); }else if(jQuery.isFunction(newClass.init)){ newClass._super.init.apply(this, arguments); } }; newClass._super = parent; jQuery.extend(newClass.prototype, parent, newMethod, { bind : function (name, data, func) { var _j_this = jQuery(this); _j_this.bind.apply(_j_this ,arguments); }, one : function (name, data, func) { var _j_this = jQuery(this); _j_this.one.apply(_j_this ,arguments); }, trigger : function (name, data) { var _j_this = jQuery(this); _j_this.trigger.apply(_j_this ,arguments); }, triggerHandler : function (name, data) { var _j_this = jQuery(this); _j_this.triggerHandler.apply(_j_this ,arguments); }, unbind : function (name, data) { var _j_this = jQuery(this); _j_this.unbind.apply(_j_this ,arguments); } }); return newClass; }, /** * @description 将函数添加到数组 * @function * @param {Array} [arr=new Array()] 将function添加到该数组 * @param {Function} func 要添加的函数 * @return {Array} 函数数组 */ funcToArray : function (arr, func) { var array = arr || new Array(); if (func) { if (func instanceof Array) { array = array.concact(func); } else if(jQuery.isFunction(func)) { array.push(func); } } return array; } }); })(ceopen.object); eclock.js if (!window.ceopen) { window.ceopen = {}; } if (!window.ceopen.lvs) { window.ceopen.lvs = {}; } if (!window.ceopen.lvs.eclock) { window.ceopen.lvs.eclock = {}; } (function(package){ var EClock = ceopen.object.createClass(null, { dom : null, date : null, timeout : null, current : null, isshut : true, timedifference : 0, init : function(arg0) { var _this = this; if(!arg0.dom) throw new Error("must designated parameter : dom"); else this.dom = arg0.dom; if(arg0.date)_this.setDate(arg0.date); //_this.initBind(); }, setDate : function(date) { var _this = this; if(date instanceof Date) { this.date = date; } else if(typeof date == "string" || typeof date == "number") { var idate = new Date(); idate.setTime(date); this.date = idate; } return _this; }, start : function() { var _this = this; _this.shut(); this.isshut = true; if(this.date == null) { _this.meizzTime(0); } else { var time1 = this.date.getTime() / 1000; var time2 = parseInt(new Date().getTime() / 1000); this.timedifference = time1 - time2; // 两端时间秒差 _this.meizzTime(this.timedifference); } }, meizzTime : function (n) { //console.log("test"); var _this = this; var newDate = new Date(); if(n!=0) newDate.setTime(newDate.getTime() + this.timedifference * 1000); // 得到一个新的时间 this.current = newDate; if(this.isshut) $(this.dom).html(newDate.toLocaleString()+' 星期'+'日一二三四五六'.charAt(newDate.getDay())); this.timeout = setTimeout(function(){ _this.meizzTime(_this.timedifference); }, 1000); }, shut : function() { if(this.timeout) clearTimeout(this.timeout); }, shutHtml : function() { this.isshut = false; }, restart : function(date) { var _this = this; if(typeof date != "undefined") { _this.setDate(date).start(); } else _this.start(); }, getCurrent : function() { if(this.current) return this.current; else throw new Error("时间似乎还没有运行!"); }, getCurrentStr : function() { if(this.current) return this.current.toLocaleString()+' 星期'+'日一二三四五六'.charAt(this.current.getDay()); else throw new Error("时间似乎还没有运行!"); }, getClient : function(){ var date = new Date(); var dateStr = date.toLocaleString()+' 星期'+'日一二三四五六'.charAt(this.current.getDay()); return {"date":date,"dateStr":dateStr}; }, resume : function() { var _this = this; this.isshut = true; if(this.current) { _this.setDate(this.current).start(); } else { _this.start(); } } }); jQuery.extend(package, { EClock : EClock }); })(ceopen.lvs.eclock); 测试 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <mce:script type="text/javascript" src="js/jquery-1.3.2.pack.js" mce_src="js/jquery-1.3.2.pack.js"></mce:script> <mce:script type="text/javascript" src="js/ceopen.object.js" mce_src="js/ceopen.object.js"></mce:script> <mce:script type="text/javascript" src="js/ceopen.lvs.eclock.js" mce_src="js/ceopen.lvs.eclock.js"></mce:script> <SCRIPT LANGUAGE="JavaScript"> var _lvs_eclock; var _lvs_eclock1; _lvs_eclock = new ceopen.lvs.eclock.EClock({ dom:"eClock", date:new Date() }); _lvs_eclock.start(); var date = new Date("2009/01/01 03:03:03"); _lvs_eclock1 = new ceopen.lvs.eclock.EClock({ dom:"eClock1", date:date.getTime() }); _lvs_eclock1.start(); </SCRIPT> </HEAD> <BODY> <div class="time1" id="eClock"></div> <br/> <div class="time1" id="eClock1"></div> </BODY> </HTML> http://download.csdn.net/source/2216195 是动态修改页面的本地时间和获取系统时间,并动态修改