Jquery TimePicker : How to dynamically change parameters

让人想犯罪 __ 提交于 2019-11-28 08:07:21

问题


I am using a 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

$('#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 . 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 .


回答1:


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

See this JS Fiddle.




回答2:


You can go for onchange event:

        $('#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/

You can use on('change'... too

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



回答3:


jQuery-UI widgets generally support an options method that allows you to change the options on an existing instance. Widget methods are called by supplying a string as the first argument to the plugin call:

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

so this should work for you:

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


来源:https://stackoverflow.com/questions/10958387/jquery-timepicker-how-to-dynamically-change-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!