jQuery 日期时间选择器 - 设置开放日期和时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7523175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Date Time Picker - Setting Opening Date and Time
提问by Roger
I'm using this nifty little date and time picker [ http://trentrichardson.com/examples/timepicker/]. How can I set the date and time for when the picker opens?
我正在使用这个漂亮的小日期和时间选择器 [ http://trentrichardson.com/examples/timepicker/]。如何设置选择器打开的日期和时间?
回答by John Zumbrum
If you're using this on a form, set it from a hidden input.
如果您在表单上使用它,请从隐藏输入设置它。
$(document).ready(function () {
$("#Date").datetimepicker({
ampm: true
});
var date = new Date(
Date.parse(
$('#DatePicker').val(),
"mm/dd/yyyy hh:MM tt"
)
);
$('#Date').datetimepicker('setDate', date);
});
HTML Form:
HTML 表单:
<input type="hidden" id="DatePicker" />
<input type="text" id="DatePicker" value="fromyourdatabase" />
回答by dinesh
Try thisThen add$('#dtpkr').datetimepicker();
This will give you the current date and time$('#dtpkr').datetimepicker('setDate', (new Date()));
尝试这个然后加$('#dtpkr').datetimepicker();
这将为您提供当前日期和时间$('#dtpkr').datetimepicker('setDate', (new Date()));
回答by William Niu
You could pass a Date
object to the setDate
method.
您可以将Date
对象传递给该setDate
方法。
$('#datetimepicker').datetimepicker().click(function() {
$(this).datetimepicker('setDate',new Date(2011, 11, 20, 8, 30));
});
See it in action: http://jsfiddle.net/william/Rkewu/1/.
看看它在行动:http: //jsfiddle.net/william/Rkewu/1/。
回答by SpoiledTechie.com
Just focus it.
集中注意力就好。
$('#totTb').datetimepicker({
timeFormat: 'HH:mm',
timeSuffix: " Z"
}).focus(function () { $('#totTb').datetimepicker('setDate', d) });
回答by Rusty Fausak
Try setting the value
attribute inside the input
element like this:
尝试像这样设置元素value
内的属性input
:
<input id="example1" value="05/05/2011" />