jQuery UI DateTimepicker - 无法隐藏时间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11506371/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:41:33  来源:igfitidea点击:

jQuery UI DateTimepicker - cannot hide the time

jquerydatetimepickertimepicker

提问by Ruben

I'm using the date time picker component from http://trentrichardson.com/examples/timepicker/. Trying to hide the time picker but my code doesn't work:

我正在使用http://trentrichardson.com/examples/timepicker/ 中的日期时间选择器组件。试图隐藏时间选择器,但我的代码不起作用:

$('#id_start_date_time').datetimepicker('option', 'showTimepicker', false);

回答by Andrew Liu

I just came across this issue. I know its been a while since this question was asked by the OP and he has probably solved the problem. Just for someone who might be encountering this issue in the future, if you want to hide the timepicker, just simply call the original jquery ui datepicker method

我刚刚遇到这个问题。我知道自从 OP 提出这个问题以来已经有一段时间了,他可能已经解决了这个问题。仅针对将来可能遇到此问题的人,如果您想隐藏时间选择器,只需调用原始的 jquery ui datepicker 方法

datepicker()

instead of

代替

datetimepicker()

回答by Miles

timepicker:false for jquery.datetimepicker

时间选择器:jquery.datetimepicker 为假

回答by sandeep kumar

i use my this code when another code not work.

当另一个代码不起作用时,我使用我的这个代码。

    $('#datetimepicker_date_to_view').datetimepicker({
            timepicker:false,
            format:'d.m.Y',
        }).on('change', function() {
            $('.xdsoft_datetimepicker').hide();
            var str = $(this).val();
            str = str.split(".");
            $('#alt_date_field').val(str[2]+'-'+str[1]+'-'+str[0]);
        });

回答by Romain R

You need to add the following option :

您需要添加以下选项:

timepicker: false

时间选择器:假

(timepicker have to be in lowercase)

(时间选择器必须是小写的)

回答by peacemaker

You must define options like this:

您必须定义如下选项:

$('#id_start_date_time').datetimepicker({
    showTimePicker: false
});

To add more options you can just separate by commas:

要添加更多选项,您可以用逗号分隔:

$('#id_start_date_time').datetimepicker({
    showTimePicker: false,
    showSecond: true,
    timeFormat: 'hh:mm:ss'
});

回答by Shaakir

I used the 'showTimepicker': true, / 'showTimepicker': false, options to show / hide the time options if not needed.

如果不需要,我使用了 'showTimepicker': true, / 'showTimepicker': false 选项来显示/隐藏时间选项。

some pages have both with time and without time options that is why i needed to use this option.

有些页面既有时间选项,也有时间选项,这就是我需要使用此选项的原因。

when i have this set to false, it hides the time options as it is designed to do but the overide

当我将此设置为 false 时,它​​会按照设计的目的隐藏时间选项,但覆盖

$.datepicker._base_gotoToday = $.datepicker._gotoToday;

causes problems. When i click on today / now button, it sets date to today but hides the calender, and when i click on the input box again nothing happens, only when i click anywhere else then and then click on the input box again does the calender show.

导致问题。当我点击今天/现在按钮时,它将日期设置为今天但隐藏日历,当我再次点击输入框时没有任何反应,只有当我点击其他任何地方然后再次点击输入框时,日历才会显示.

I have removed the line

我已删除该行

$('.ui-datepicker-today', $dp).click();

which seems to have solved the problem.

这似乎解决了这个问题。

It has lost the ability to close when i click the today button but i can live with that

当我点击今天按钮时,它已经失去了关闭的能力,但我可以忍受

回答by abhishek kumar

this code working fine:

这段代码工作正常:

  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.min.css">
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.min.js"></script>
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js"></script>


<input class="form-control" id="datetimepicker" type="text" name="date" placeholder="Date">

<script>
$('#datetimepicker').datetimepicker({
    format:'Y-m-d',timepicker: false,
});
</script>

Also,Include jquery library

此外,包括 jquery 库