仅在单击日历图像时才打开Jquery日期时间选择器

问题描述 投票:-1回答:1

我正在使用Jquery datetimepicker。我不想在跳到文本框时打开日历。我想在文本框的末尾放置一个日历图像。在日历图像上单击一次时,我要打开日历以选择日期时间。此选项有效。如果我仅使用日期选择器控件-我只能在其中选择日期-则无法使用。

在以下代码中,Datepicker完全按照我想要的方式工作,没有时间选项。我拥有日期和时间选项,当我单击图像时,它只能打开一次。

DatePicker:

 $("#ImageDate").datepicker({
      dateFormat: 'mm/dd/yy',
      changeMonth: true,
      changeYear: true,
      showOn: 'button',
      buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif"
}); 

Datetimepicker:

$("#ImageDate1").datetimepicker({
       autoOpen: false,
       showOn: 'button',
       buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
       buttonImageOnly: true,
       format: 'm/d/Y H:i',
});
jquery datetimepicker
1个回答
0
投票

您需要在点击该图像时触发日期选择器这是可能帮助您的示例。...

Js代码:

$(function() {
  $('#startTime1Trigger').on('click', function(){
    var $t = $(this),
        $tp = $(this).parent().siblings('.timepicker').first();

    if ($tp.timepicker())
      $('#startTime1').timepicker('show');
  });
});

HTML代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.10.0/jquery.timepicker.min.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-timepicker/1.10.0/jquery.timepicker.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>

<label for="startTime1">* Proposed Start Time:</label>
<div class="input-group">
  <input class="timeinput form-control timepicker timepicker-with-dropdown text-center" id="startTime1" name="startTime1" placeholder="Start Time 1">
  <span class="input-group-addon">
        <i class="fa fa-arrow-down fa-fw" id="startTime1Trigger" aria-hidden="true"></i>
    </span>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.