随笔 - 3460, 文章 - 0, 评论 - 739, 阅读 - 1197万
  管理

[jQuery筆記] 好用的日期函式 datepicker

Posted on   lzhdim  阅读(1988)  评论(2编辑  收藏  举报

最近在学习 javascript,当然首推的就是 jQuery 了,之前因為懒得做日期表单,因為日期表单需要三种栏位,一个是年,一个是月,一个是日,相当麻烦,一直在那边 for 迴圈也不是办法,虽然那是个解决方法,然后我之前用了xt:Commerce 这套 opensource的程式码,把日期函式取出来:[Html] javascript 好用的时间日历表,不过我认為这方法也太麻烦,因為 jQuery 一行就可以解决的事情,干麼还要用那个方法呢?

再来呢介绍一下怎麼使用日期函式
步骤一:加上 jQuery 套件到 head 跟 /head 之间

<script type="text/javascript" src="jquery.js"></script>
<!--
或者是
-->
<script src="http://code.jquery.com/jquery-latest.js"></script>

步骤二:加上 ui.datepicker.css 跟 ui.datepicker.js jQuery UI Date Picker CSS and the jQuery UI Date Picker Javascript

<style type="text/css">@import url(ui.datepicker.css);</style>
<script type="text/javascript" src="ui.datepicker.js"></script>

步骤三:教大家使用四种基本方法:

1. 最基本的语法 (mm/dd/yyyy).

jQuery(function($){
  $('#example1').datepicker();
});

2. 加上旁边图示也可以进行操作

$('#example2').datepicker({showOn: 'both', showOtherMonths: true,
        showWeeks: true, firstDay: 1, changeFirstDay: false,
        buttonImageOnly: true, buttonImage: 'calendar.gif'});

3. 改变时间格式

$('#example4').datepicker({dateFormat: 'yy-mm-dd', showOn: 'both',
          buttonImageOnly: true, buttonImage: 'calendar.gif'});

4. 选择日期范围

$('#exampleRange').datepicker({rangeSelect: true, firstDay: 1, showOn: 'both',
          buttonImageOnly: true, buttonImage: 'calendar.gif'});

5. 初始话时间,加7天

#
# 增加7天时间
#
$('input selector').datepicker({defaultDate: +7});

程式执行画面:
102 (by appleboy46)
Demo介绍

Demo档案下载:datepickerdemo coreuidatepicker
参考网站:
http://docs.jquery.com/UI/Datepicker
http://marcgrabanski.com/code/ui-datepicker/
http://kelvinluck.com/assets/jquery/datePicker/v2/demo/

相关主题

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2025年3月7日 星期五 【蛇】己卯月乙亥日 乙巳年 二月初八
您的IP:3.144.31.80,操作系统:未知操作系统,浏览器:未知浏览器
Copyright (C) 2000-2025 Lzhdim Software All Rights Reserved
点击右上角即可分享
微信分享提示