在页面显示日期和当前时间,可以读秒

需要写一个自定义的插件(jquery-timer-1.0.js)


/**
 * jQuery日期插件
 * 匿名函数
 */
(function($) {
	/** 为jQuery添加对象的方法 */
	$.prototype.test1=function(){
		this.html("dddd");
	}
	/** 为jQuery批量添加对象的方法 */
	$.fn.extend({
		runtime:function(){
			/** 创建日期对象 */
			var d = new Date();
			/** 定义数组封装数据 */
			var arr = new Array();
			/** 获取年*/
			arr.push(d.getFullYear()+"年");
			/** 获取月0-11月*/
			arr.push($.calc(d.getMonth()+1)+"月");
			/** 获取日*/
			arr.push($.calc(d.getDate())+"日");
			/** 获取星期0-6,要用数组来封装,通过角标来判断星期几*/
			var week =$.weeks[d.getDay()];
			arr.push(" "+week+" ");
			/** 获取小时*/
			arr.push($.calc(d.getHours())+":");
			/** 获取分钟*/
			arr.push($.calc(d.getMinutes())+":");
			/** 获取秒*/
			arr.push($.calc(d.getSeconds()));
			
			this.html(arr.join(""));
			var t =this
			/** 开启定时器*/
			setTimeout(function() {
				t.runtime();
			}, 1000);
		},
		
	});
	/** 为jQuery添加静态的方法*/
	$.extend({
		weeks:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
		calc :function(str){
			return str>9?str:"0"+str;
		}
	});
})(jQuery);

写一个jsp页面,在页面中要引入自定义的插件


<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  	<title>办公管理系统</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="Cache-Control" content="no-cache, must-revalidate"/>
	<meta name="Keywords" content="keyword1,keyword2,keyword3"/>
	<meta name="Description" content="网页信息的描述" />
	<meta name="Author" content="gdcct.gov.cn" />
	<meta name="Copyright" content="All Rights Reserved." />
	<link href="${path }/logo.ico" rel="shortcut icon" type="image/x-icon" />
	<link rel="stylesheet" type="text/css" href="${path}/css/common/global.css"/>
	<script type="text/javascript" src="${path}/js/jquery-1.11.3.min.js"></script>
	<script type="text/javascript" src="${path}/js/jquery-migrate-1.2.1.min.js"></script>
	<span style="background-color: rgb(255, 0, 0);"><script type="text/javascript" src="${path}/js/jquery-timer-1.0.js"></script>引入插件</span>
	<script type="text/javascript">
		/**当html页面被浏览器加载完  */
		$(document).ready(function() {
			/**显示当前系统运行的时间  */
			$("#time").runtime();
			/** 按点击图标次数绑定事件*/
			$("#ShowNav").toggle(
				function() {
					/** 获取父窗口的frameset(Id为tstMain)*/
					var tst =$("#tstMain",parent.document);
					$("#headtitle").hide();
					tst.attr("rows","12,*");
					/** 更改图标*/
					$(this).attr("src","${path}/images/system/top_yc.gif");
					$("#nav_title").attr("title","显示菜单栏");
				},
				function(){
					/** 获取父窗口的frameset(Id为tstMain)*/
					var tst =$("#tstMain",parent.document);
					$("#headtitle").show();
					tst.attr("rows","82,*");
					/** 更改图标*/
					$(this).attr("src","${path}/images/system/top_xs.gif");
					$("#nav_title").attr("title","隐藏菜单栏");
			});
		});
	</script>
  </head>

 <body class="headbody">
	<div class="headtitle" id="headtitle">
    	<div class="headlogo"><img src="${path}/images/system/logo.gif" />
    	</div>
        <div class="headmenutop">
        	
        	<a class="headtopout" title="退出系统" href="javascript:void(0);" οnclick="exit();">安全退出</a>
        	<a class="headtopout" title="密码修改" href="javascript:void(0);" οnclick="password();">密码修改</a>
			<div class="titlexx">
				<span style="font-size:14px;">${session_user.name } 您好,</span>  
				<span id="time" style="color:#fff;font-size:14px;"></span>
				
			</div>
        </div>
    </div>
    <div class="yctopdiv">
      	<a href="javascript:void(0);" class="t_link" title="隐藏菜单栏" id="nav_title">
		<img src="${path}/images/system/top_yc.gif" id="ShowNav"/>
		<!--隐藏时反显示的图片<img src="images/system/top_xs.gif" />--></a>
    </div>
  </body>
</html>

写完即可运行测试



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值