jQuery-UI datepicker默认日期 [英] jQuery-UI datepicker default date

查看:79
本文介绍了jQuery-UI datepicker默认日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用jQuery-UI datepicker时遇到了问题,我进行了搜索,但没有找到答案.我有以下代码:

I have a problem with the jQuery-UI datepicker, I have searched and searched but I didn't find the answer. I have the following code:

<script type="text/javascript">
$(function() {               
    $("#birthdate" ).datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: '1920:2010',
        dateFormat : 'dd-mm-yy',
        defaultDate: '01-01-1985'
    });
});
</script>

我希望当用户单击#birthdate输入时,将当前日期选择为01-01-1985,现在设置当前日期.

I want that when the user click in the #birthdate input that the current date selected to be 01-01-1985, now it's setting the current date.

推荐答案

请尝试传入Date对象.我看不到为什么它不能按照您输入的格式工作:

Try passing in a Date object instead. I can't see why it doesn't work in the format you have entered:

<script type="text/javascript">
$(function() {               
    $("#birthdate" ).datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: '1920:2010',
        dateFormat : 'dd-mm-yy',
        defaultDate: new Date(1985, 00, 01)
    });
});
</script>

http://api.jqueryui.com/datepicker/#option-defaultDate

通过< 日期对象或作为字符串 当前dateFormat或多个 从今天开始的天数(例如+7)或一个字符串 价值和期间("y"代表几年, "m"代表数月,"w"代表数周,"d"代表 天,例如'+ 1m + 7d'),或对于null 今天.

Specify either an actual date via a Date object or as a string in the current dateFormat, or a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null for today.

这篇关于jQuery-UI datepicker默认日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆