jQuery Datetimepicker XDsoft:如何从内联日历中获取价值?

时间:2014-06-08 12:23:38

标签: javascript jquery datepicker

我使用XDSoft的jQuery Datetimepicker插件:http://xdsoft.net/jqplugins/datetimepicker/

我将日历显示为内联。这是我的代码:

HTML:

<input type="text" id="start_date">

JS:

jQuery('#start_date').datetimepicker({
  format:'d.m.Y H:i',
  inline:true
});

我的问题:当我在前端选择一个日期时,输入字段不会将所选日期作为值。我需要做出哪些更改或需要添加什么?

3 个答案:

答案 0 :(得分:1)

使用date time picker event

<强> HTML

<input type="hidden" id="start_date">

<强> JS

var $startDate = $('#start_date');

$startDate.datetimepicker({
  inline:true,
  sideBySide: true
});

$startDate.on('dp.change', function() {
  var selectedDate = $(this).val();
  alert(selectedDate);
});

<强> JS Fiddle Demo

答案 1 :(得分:0)

Onchange Event

获取价值

试试这个

onChangeDateTime:function(dp,$input){
            $('#datePickValue').text($input.val());
        }

完整代码看起来像这样

jQuery('#start_date').datetimepicker({
  format:'d.m.Y H:i',
  inline:true,
  onChangeDateTime:function(dp,$input){
    $('#start_date').text($input.val()); // change the div as per your need - change the text as val ( it depends on the field)
  });

答案 2 :(得分:0)

$('#start_date').datetimepicker({
  format:"d/m/Y H:i:s",
  inline:true,
  step:5,
  onChangeDateTime:  function (ct,$i) {
    $('#start_date').val(ct.dateFormat('d/m/Y H:i'));
  }
});

尝试这个..它对我有用,所以它也适用于你...快乐编码..