Jquery UI 中datepicker使用

      jQuery是一个js库,主要提供的功能是选择器,属性修改和事件绑定等等。jQuery UI则是在jQuery的基础上,利用jQuery的扩展性,设计的插件。提供了一些常用的界面元素,诸如对话框、拖动行为、改变大小行为等等。
          在使用jQuery ui的过程中,发现jQuery ui的功能很强大,其中日期选择插件datepicker是一个配置灵活的插件,我们可以自己定义其展开方式,包括日期格式、语言、限制日期选择范围、添加相关按钮以及其他导航等。具体步骤:(1)引入jquery.js;(2)引入ui下面的jquery.ui.core.js、jquery.ui.widget.js、jquery.ui.datepicker.js;(3)如果想设置日历为中文形式,需要引入ui->i18n下面的jquery.ui.datepicker-zh-CN.js;(4)在HTML中需为input type="text"设置ID;(5)写js代码,引入datepicker定义的函数以及各参数的设置。(6)可引入jQuery ui中相应的样式也可根据自己的需要修改样式。(如果需要显示时分秒:1需下载jquery-ui-timepicker-addon.js,并在页面加载;2页面添加样式
 
 
  1. .ui-timepicker-div .ui-widget-header { margin-bottom8px; }  
  2. .ui-timepicker-div dl { text-alignleft; }  
  3. .ui-timepicker-div dl dt { height25pxmargin-bottom-25px; }  
  4. .ui-timepicker-div dl dd { margin0 10px 10px 65px; }  
  5. .ui-timepicker-div td { font-size90%; }  
  6. .ui-tpicker-grid-label { backgroundnonebordernonemargin0padding0; }  ;3$("#date").datetimepicker();//显示时分秒  $("#datetime").datepicker(); // 显示日期  $("#datetime").timepicker(); // 显示时分秒 
图1:
 

图2:

 
 下面是本人做的完整实例,可供参考,若有什么问题望大家指正。
  
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>datepicker</title>
 <link rel="stylesheet" href="jquery-ui-1.10.4.custom/development-bundle/themes/base/jquery.ui.all.css">
<link rel="stylesheet" href="jquery-ui-1.10.4.custom/development-bundle/demos/demos.css">
</head>
<body>
<div><input type="text" id="date"></div>
</body>
<script src="jquery-ui-1.10.4.custom/js/jquery-1.10.2.js" type="text/javascript"></script>
	<script src="jquery-ui-1.10.4.custom/development-bundle/ui/jquery.ui.core.js"></script>
	<script src="jquery-ui-1.10.4.custom/development-bundle/ui/jquery.ui.widget.js"></script>
	<script src="jquery-ui-1.10.4.custom/development-bundle/ui/jquery.ui.datepicker.js"></script>
  <script type="text/javascript" src="jquery-ui-1.10.4.custom/js/jquery-ui-timepicker-addon.js"></script>
	<script src="jquery-ui-1.10.4.custom/development-bundle/ui/i18n/jquery.ui.datepicker-zh-CN.js"></script>
 <script type="text/javascript">
$(function(){
//1.简单引用的实现,实现的样式如图1:
    $("#date").datepicker();
	2.可修改年月的样式实现,如图2:
   $("#date").datepicker({
		changeYear : true,
		changeMonth : true,
		numberOfMonths : 1,
		showButtonPanel: true
		});
});
//3显示时分秒,如图3
$("#date").datetimepicker();
</script>

</html>

图3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值