[英]Set default bootstrap date and datetime values at page load using javascript
I'm using date and datetime functions for my textfields, when I click at textfield it shows the calender and I select date and datetime from calender and my functions are 我在文本字段中使用日期和日期时间函数,当我单击文本字段时,它显示了日历,并且我从日历中选择了日期和日期时间,而我的函数是
$('.date-picker').datepicker({
rtl: Metronic.isRTL(),
autoclose: true,
format: "mm/dd/yyyy",
startDate: new Date()
});
$(".datetime-picker").datetimepicker({
autoclose: true,
isRTL: Metronic.isRTL(),
format: "mm/dd/yyyy - hh:ii",
pickerPosition: (Metronic.isRTL() ? "bottom-right" : "bottom-left")
});
What I want is when I load my page the values set by automatically current date and datetime. 我想要的是当我加载页面时,由当前日期和日期时间自动设置的值。 I search about these functions but cannot set default values of current date and datetime.
我搜索了这些功能,但无法设置当前日期和日期时间的默认值。 I also try
defaultdate: new Date() OR defaultdate: '03/09/2015'
but didn't work for me. 我也尝试使用
defaultdate: new Date() OR defaultdate: '03/09/2015'
但对我不起作用。 How could I do this? 我该怎么办?
I've done this but my programme is not working properly I don't know why is this happening? 我已经做到了,但是我的程序无法正常运行,我不知道为什么会这样?
Use setDate as shown below, (this code should be on the document ready event) 使用setDate,如下所示,(此代码应在文档准备事件中)
$('.date-picker').datepicker({
rtl: Metronic.isRTL(),
autoclose: true,
format: "mm/dd/yyyy"
}).datepicker("setDate", new Date());
Sample from my code: 我的代码示例:
Display current Date: 显示当前日期:
buildLogDateToTxt.datepicker({
showOn: "button",
buttonImage: "images/calendar.png",
buttonImageOnly: true,
onClose: function (dateText, inst) {
this.fixFocusIE = true;
this.focus();
}
}).datepicker("setDate", new Date());
Set previous date: 设置上一个日期:
buildLogDateFromTxt.datepicker({
showOn: "button",
buttonImage: "images/calendar.png",
buttonImageOnly: true,
onClose: function (dateText, inst) {
this.fixFocusIE = true;
this.focus();
}
}).datepicker("setDate", "-7");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.