Javascript Jquery TimePicker:如何动态更改参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10958387/
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
Jquery TimePicker : How to dynamically change parameters
提问by geeky_monster
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 . 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 .
我希望当第一次选择 timePicker 时,第二次的 'minTime' 参数被改变。基本上我试图收集某些活动的开始时间和结束时间。而且我希望第二个输入框显示来自第一个输入字段(开始时间)本身的值的选项。
回答by Ranhiru Jude Cooray
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 Fiddle。
回答by Raghav
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
您也可以使用 on('change'...
$('#startTime').on('change', function() {
$('#endTime').timepicker('option', 'minTime', $(this).val());
});
回答by mu is too short
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:
jQuery-UI 小部件通常支持一种options
方法,该方法允许您更改现有实例上的选项。通过提供一个字符串作为插件调用的第一个参数来调用小部件方法:
$(...).widget_name('method_name', arg...)
so this should work for you:
所以这应该适合你:
$('#endTime').timepicker('option', 'minTime', new_min_time)