Jquery ui datepicker时间控件的使用,引入以下的JS文件。
<script language="javascript" src="jquery_ui/jquery.ui.core.js"></script>
<script language="javascript" src="jquery_ui/jquery.ui.datepicker.js"></script>
<script language="javascript" src="jquery_ui/jquery.ui.datepicker-zh-CN.js"></script>
<link rel="stylesheet" href="jquery_ui/jquery.ui.core.css" type="text/css" media="screen" title="core css file" charset="utf-8" />
<link rel="stylesheet" href="jquery_ui/jquery.ui.datepicker.css" type="text/css" media="screen" title="core css file" charset="utf-8" />
<link rel="stylesheet" href="jquery_ui/jquery.ui.theme.css" type="text/css" media="screen" title="core css file" charset="utf-8" />
<link rel="stylesheet" href="jquery_ui/pack_datepicker.css" tpack_datepicker.cssype="text/css" media="screen" title="core css file" charset="utf-8" />
pack_datepicker.css是调整样式的文件,默认中文情况下很不好看,用 pack_datepicker.css调整样式
.ui-datepicker .ui-datepicker-title select {font-size:1em; margin:1px 0; }
.ui-datepicker select.ui-datepicker-month-year {width: 100%;}
.ui-datepicker select.ui-datepicker-month,
.ui-datepicker select.ui-datepicker-year { width: 40%;}
.ui-datepicker .ui-datepicker-title select.ui-datepicker-year { float: left; }
/* 控制字体大小
.ui-datepicker-div, .ui-datepicker-inline, #ui-datepicker-div {font-size:1.2em}
*/
最后效果如下:
调用代码:
<script type="text/javascript"> $(function() { $('#datepicker').datepicker( { changeMonth : true, changeYear : true, showOn : 'button', buttonImage : '${pageContext.request.contextPath}/script/jquery_ui/images/calendar.gif', buttonImageOnly : true, minDate : '-4y', maxDate : '+4y' }); }); </script>