简体   繁体   English

jQuery timepicker的两个实例

[英]Two instances of jQuery timepicker

I have tow different jQuery functions, one is for hours and the other one for minutes. 我有两个不同的jQuery函数,一个是几个小时,另一个是几分钟。

$('#hour_timepicker').timepicker({
    timeFormat: 'h',
    interval: 1,
    dynamic: false,
    dropdown: true,
    scrollbar: true
});

The code above works perfectly well. 上面的代码运行良好。 However my next function, which has to show the minutes does not work, 但是我的下一个必须显示分钟的功能不起作用,

$('#minute_timepicker').timepicker({
    timeFormat: 'm',
    interval: 10,
    dynamic: true,
    dropdown: true,
    scrollbar: true
});

No matter what value I select from the minute_timepicker , it shows completey random numbers. 无论我从minute_timepicker选择什么值,它都会显示完整的随机数。

Here are the inputs aswell: 这也是输入:

<label id="hour_timepicker_label">Slect time</label>
<input id="hour_timepicker" type="text"/>
<label>:</label>
<input id="minute_timepicker" type="text"/>

Can anyone help please? 有人可以帮忙吗? Thank you. 谢谢。

Link to timepicker library : http://jonthornton.github.io/jquery-timepicker/ 链接到timepicker库http : //jonthornton.github.io/jquery-timepicker/

I think the issue is that this library isn't really designed to pick the minutes seperately, if you had to do it you would need to set the step to 60 for hour (so it will only show in one hour increments), and then for the minutes you would need to restrict it to only show some arbitrary hour so it won't repeat, and then set the step to 10 so it will show in 10 minute increments. 我认为问题在于此库并不是真正为单独选择分钟而设计的,如果必须这样做,则需要将步骤设置为60小时(这样,它只会以一小时为增量显示),然后对于分钟,您需要将其限制为仅显示任意一个小时,这样它就不会重复,然后将步长设置为10,以便以10分钟为增量显示。

 $('#hour_timepicker').timepicker({ timeFormat: 'H', interval: 1, step: 60, dynamic: false, dropdown: true, scrollbar: true }); $('#minute_timepicker').timepicker({ timeFormat: 'i', step: 10, dynamic: true, dropdown: true, scrollbar: true, minTime: '12:00am', maxTime: '12:59am' }); 
 <link href="https://cdn.jsdelivr.net/npm/timepicker@1.11.14/dist/jquery.timepicker.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/timepicker@1.11.14/dist/jquery.timepicker.min.js"></script> <label id="hour_timepicker_label">Slect time</label> <input id="hour_timepicker" type="text"/> <label>:</label> <input id="minute_timepicker" type="text"/> 

try i intstead of m on your second function. 尝试让i代替m代替您的第二个功能。

ie

$('#minute_timepicker').timepicker({
    timeFormat: 'i',
    interval: 10,
    dynamic: true,
    dropdown: true,
    scrollbar: true
});

sorry if this doesn't work. 对不起,如果这不起作用。

I'm suggesting this because on the documentation, it has this: 我建议这样做是因为在文档中,它具有以下内容:

$('#timeformatExample1').timepicker({ 'timeFormat': 'H:i:s' });

H -> hours , i -> minutes and s -> seconds H -> hoursi -> minutess -> seconds

Based on the documentation for that library, the timeFormat is defined as: 根据该库的文档,timeFormat定义为:

timeFormat How times should be displayed in the list and input element. timeFormat时间应如何在列表和输入元素中显示。 Uses PHP's date() formatting syntax . 使用PHP的date()格式语法 Characters can be escaped with a preceeding double slash (eg H\\hi). 可以使用前面的双斜杠来转义字符(例如,H \\ hi)。 Alternatively, you can specify a function instead of a string, to use completely custom time formatting. 另外,您可以指定一个函数而不是一个字符串,以使用完全自定义的时间格式。 In this case, the format function receives a Date object and is expected to return a formatted time as a string. 在这种情况下,格式函数将接收Date对象,并期望以字符串形式返回格式化时间。 default: 'g:ia' 默认值:'g:ia'

and the PHP formatting syntax for minutes is i 并分钟PHP语法格式是i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM