我需要创建用于jquery UI的小时和分钟选择的文本框。这是我的代码:
var myControl1 = {
create: function (tp_inst, obj, unit, val, min, max, step) {
$('<input class="ui-timepicker-input" placeholder="HH" value="' + val + '" style="width:50%">')
.appendTo(obj)
.text({
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();
}
});
return obj;
// generate whatever controls you want here, just return obj
},
options: function (tp_inst, obj, unit, opts, val) {
if (typeof (opts) == 'string' && val !== undefined)
return obj.find('.ui-timepicker-input').text(opts, val);
return obj.find('.ui-timepicker-input').text(opts);
// if val==undefined return the value, else return obj
},
value: function (tp_inst, obj, unit, val) {
if (val !== undefined)
return obj.find('.ui-timepicker-input').text('value', val);
return obj.find('.ui-timepicker-input').text('value');
// if val==undefined return the value, else return obj
}
}
$('#testid').datetimepicker(
{
controlType: myControl1
}
);
通过使用此代码,文本框已创建小时和分钟,但更改事件不起作用(即,不使用新输入的值进行更新,考虑默认值00:00)。