简体   繁体   English

Jquery TimePicker:如何动态更改参数

[英]Jquery TimePicker : How to dynamically change parameters

I am using a Jquery Timepicker . 我正在使用Jquery Timepicker。

I have two input fields - to Accept times . 我有两个输入字段 - 接受时间。

<input id="startTime"  size="30" type="text" />
<input id="endTime"  size="30" type="text" />

I am using a Jquery UI timer as per documentation 我按照文档使用Jquery UI计时器

$('#startTime').timepicker({
    'minTime': '6:00am',
    'maxTime': '11:30pm',
    'onSelect': function() {
        //change the 'minTime parameter of #endTime <--- how do I do this ?
     }
});
$('#endTime').timepicker({
    'minTime': '2:00pm',
    'maxTime': '11:30pm',
    'showDuration': true
});

I want that when the first timePicker is selected , the 'minTime' parameter for the second gets changed . 我希望在选择第一个timePicker时,第二个'minTime'参数会被更改。 Basically I am trying to collect the start time and end time for certain activity . 基本上我正在尝试收集某些活动的开始时间和结束时间。 And I want that the second input box shows the options from the value of the first input field (start time ) itself . 我希望第二个输入框显示第一个输入字段(开始时间)本身的值的选项。

You would do something like this, 你会做这样的事情,

$('#startTime').timepicker({
                'minTime': '6:00am',
                'maxTime': '11:30pm',
                    'onSelect': function() {

                    $('#endTime').timepicker('option', 'minTime', $(this).val());                        
              }
            });

What you are doing here is that in the onSelect function of the #startTime , you set the option minTime of #endTime to the value of #startTime 你在这里做的是,在onSelect的功能#startTime ,你设置的选项minTime#endTime到的值#startTime

See this JS Fiddle . 看到这个JS小提琴

You can go for onchange event: 你可以参加onchange活动:

        $('#startTime').timepicker();

        $('#endTime').timepicker({
            'minTime': '12:00am',
            'showDuration': true
        });

        $('#startTime').on('changeTime', function() {
            $('#endTime').timepicker('option', 'minTime', $(this).val());
        });

I modified the code a bit posted in first reply here is the working fiddle for it http://jsfiddle.net/NXVy2/215/ 我在第一个回复中修改了一些代码,这里是它的工作小提琴http://jsfiddle.net/NXVy2/215/

You can use on('change'... too 你也可以使用('改变'......)

    $('#startTime').on('change', function() {
        $('#endTime').timepicker('option', 'minTime', $(this).val());
    });

jQuery-UI widgets generally support an options method that allows you to change the options on an existing instance. jQuery-UI小部件通常支持一种options方法,允许您更改现有实例上的选项。 Widget methods are called by supplying a string as the first argument to the plugin call: 通过提供字符串作为插件调用的第一个参数来调用Widget方法:

$(...).widget_name('method_name', arg...)

so this should work for you: 所以这对你有用:

$('#endTime').timepicker('option', 'minTime', new_min_time)

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

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