Bootstrap 3 Datepicker v4-设置默认日期 [英] Bootstrap 3 Datepicker v4 - set default date

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

问题描述

im使用此datetimepicker http://eonasdan.github.io/bootstrap-datetimepicker/在我的编辑表单中.从可变日期开始,我无法在此datetimepicker中设置默认值.如果我在输入元素上使用$('#edit_cost_date').val(json[0]['date']);,则输入中的值是正确的,但是如果我打开datetimepicker,我看到标记的不是输入中的日期,而是实际日期.

im using this datetimepicker http://eonasdan.github.io/bootstrap-datetimepicker/ in my edit form. Im not able to set up default value in this datetimepicker from my variable date. If I use $('#edit_cost_date').val(json[0]['date']); on input element, the value in input is right but if i open datetimepicker i see that marked is not the date in input but actual date.

var date = json[0]['date'];
$(function () {
    $('#datetimepicker-edit-cost').datetimepicker({
        locale: 'cs',
        format:'DD.MM.YYYY'
    });
});

推荐答案

您确定您的date变量是Date对象吗?如果不是,则需要设置默认日期,如下所示:

Are you sure your date variable is a Date object? If it is not, you will need to set the default date like this:

var date = json[0]['date'];
$(function () {
    $('#datetimepicker-edit-cost').datetimepicker({
        locale: 'cs',
        format:'DD.MM.YYYY',
        defaultDate: new Date(date)
    });
});

有关该插件的date属性的更多信息:

More information about the date property for that plugin:

http://eonasdan.github.io/bootstrap-datetimepicker/Functions/#date

date([newDate])

date([newDate])

采用newDate字符串,日期,时刻,空参数,并为其设置组件模型当前时刻.传递空值会取消设置组件模型的当前时刻.通过使用带有options.format和options.useStrict组件配置的矩量库对newDate参数进行解析.

Takes newDate string, Date, moment, null parameter and sets the components model current moment to it. Passing a null value unsets the components model current moment. Parsing of the newDate parameter is made using moment library with the options.format and options.useStrict components configuration.

投掷

TypeError-如果无法解析newDate

TypeError - in case the newDate cannot be parsed

发射

change.dp-如果newDate与当前时刻不同

change.dp - In case newDate is different from current moment

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

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