Bootstrap datetimepicker 每次都给出相同的日期
Bootstrap datetimepicker gives same date everytime
我有一个 bootstrap 日期时间选择器。看起来有问题(或者我没有做正确的事情)。我得到 same date/time 即使我修改了我的日期选择器。
我正在使用这个插件:
bootstrap-datetimepicker
https://eonasdan.github.io/bootstrap-datetimepicker/
这是我的日期选择器代码:
initializeDatePickers : function(){
var $datetimepicker = $(this.el).find('#datetimepicker');
$datetimepicker.datetimepicker({
minDate: new Date(),
defaultDate: new Date(),
});
},
<!-- HTML code -->
<div class="form-group">
<label for="datetimepicker">Start From</label>
<div class="input-group date" id="datetimepicker">
<input type="text" name="startFrom" class="form-control" required data-error="select date and time" />
</div>
</div>
我使用以下代码获取数据:
var data = $('#scheduleForm').serializeArray();
var schedule = {'startFrom': this.fetchData(data, 'startFrom')};
问题:
当我第一次 select bootstrap 日期选择器时,它会打印出默认时间。假设我做了改变,它仍然打印旧时间。
我错过了什么吗?
我无法弄清楚你代码的问题。你的js还不够
不过我举了个例子。似乎有效。
$(function() {
var $datetimepicker = $('#datetimepicker');
$datetimepicker.datetimepicker({
minDate: new Date(),
defaultDate: new Date()
});
$datetimepicker.on('dp.change', function() {
console.log($(this).data("DateTimePicker").date());
//var data = $('#scheduleForm').serializeArray();
//console.log(data);
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.45/js/bootstrap-datetimepicker.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.45/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<form id='test-form'>
<div class="form-group">
<label for="datetimepicker">Start From</label>
<div class="input-group date">
<input id="datetimepicker" type="text" name="startFrom" class="form-control" required data-error="select date and time" />
</div>
</div>
</form>
我有一个 bootstrap 日期时间选择器。看起来有问题(或者我没有做正确的事情)。我得到 same date/time 即使我修改了我的日期选择器。
我正在使用这个插件:
bootstrap-datetimepicker https://eonasdan.github.io/bootstrap-datetimepicker/
这是我的日期选择器代码:
initializeDatePickers : function(){
var $datetimepicker = $(this.el).find('#datetimepicker');
$datetimepicker.datetimepicker({
minDate: new Date(),
defaultDate: new Date(),
});
},
<!-- HTML code -->
<div class="form-group">
<label for="datetimepicker">Start From</label>
<div class="input-group date" id="datetimepicker">
<input type="text" name="startFrom" class="form-control" required data-error="select date and time" />
</div>
</div>
我使用以下代码获取数据:
var data = $('#scheduleForm').serializeArray();
var schedule = {'startFrom': this.fetchData(data, 'startFrom')};
问题:
当我第一次 select bootstrap 日期选择器时,它会打印出默认时间。假设我做了改变,它仍然打印旧时间。 我错过了什么吗?
我无法弄清楚你代码的问题。你的js还不够
不过我举了个例子。似乎有效。
$(function() {
var $datetimepicker = $('#datetimepicker');
$datetimepicker.datetimepicker({
minDate: new Date(),
defaultDate: new Date()
});
$datetimepicker.on('dp.change', function() {
console.log($(this).data("DateTimePicker").date());
//var data = $('#scheduleForm').serializeArray();
//console.log(data);
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.45/js/bootstrap-datetimepicker.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.45/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<form id='test-form'>
<div class="form-group">
<label for="datetimepicker">Start From</label>
<div class="input-group date">
<input id="datetimepicker" type="text" name="startFrom" class="form-control" required data-error="select date and time" />
</div>
</div>
</form>