2015-11-10 51 views
0

Jquery的dateTimePicker的事件我使用Jquery DateTimePicker和我加入JavaScript庫的輸入元素,因爲默認情況改變的時候,我們可以用滑塊或只選擇框更改時間。上輸入文本

我的輸入工作正常(我有一個輸入的小時和另一個分鐘),但我想添加一個事件到我的輸入onChange或onKeyPress設置一些限制爲「如果該值是> 59那麼值== 59「

create: function(tp_inst, obj, unit, val, min, max, step){ 
    $('<input class="ui-timepicker-input" value="'+val+'" style="width:50%">') 
     .appendTo(obj) 
     .spinner({ 
      min: min, 
      max: max, 
      step: step, 
      change: function(e,ui){ // key events 
        // don't call if api was used and not key press 
        if(e.originalEvent !== undefined) 
         tp_inst._onTimeChange(); 
        tp_inst._onSelectHandler(); 
       }, 
      spin: function(e,ui){ // spin events 
        tp_inst.control.value(tp_inst, obj, unit, ui.value); 
        tp_inst._onTimeChange(); 
        tp_inst._onSelectHandler(); 
       } 
     }); 
    return obj; 
}, 
options: function(tp_inst, obj, unit, opts, val){ 
    if(typeof(opts) == 'string' && val !== undefined) 
     return obj.find('.ui-timepicker-input').spinner(opts, val); 
    return obj.find('.ui-timepicker-input').spinner(opts); 
}, 
value: function(tp_inst, obj, unit, val){ 
    if(val !== undefined) 
     return obj.find('.ui-timepicker-input').spinner('value', val); 
    return obj.find('.ui-timepicker-input').spinner('value'); 
} 

我不知道我可以在輸入文本中添加事件。

回答

1

好吧,我解決我的問題與此:

$(document).on('keypress', '.ui-timepicker-input', function(ev){ 
    alert("ok"); 
    }); 

我希望這將有助於。