It is impossible to highlight the text on a un-focus textbox. An alternative solution to achieve your functionality is to use a <div> displaying the time information instead of using <input> element. Here is the extended method of timespinner plugin.
$.extend($.fn.timespinner.methods,{
textbox: function(jq){
return jq;
},
highlightValue: function(jq){
return jq.each(function(){
var target = this;
var state = $.data(target, 'timespinner');
var opts = state.options;
var t = $(target);
var tb = t.timespinner('textbox');
if (!state.label){
var span = t.timespinner('textbox').parent().css('position','relative');
state.label = $('<div></div>').appendTo(span);
state.label.css({
position:'absolute',
left:0,
top:0,
padding:'0 2px',
background:'#fff'
});
state.label.bind('click', function(e){
var part = $(e.target).closest('span');
if (part.length){
var index = parseInt(part.attr('t-index'));
opts.highlight = index;
highlight(target, index);
}
tb.focus();
state.label.hide();
});
tb.bind('blur', function(){
state.label.show();
setColor();
});
var sopts = $(target).spinner('options');
var onChange = sopts.onChange;
sopts.onChange = function(newValue, oldValue){
setColor();
onChange.call(this, newValue, oldValue);
}
}
state.label._outerWidth(tb._outerWidth())._outerHeight(tb._outerHeight());
state.label.css('line-height', tb._outerHeight()+'px');
setColor();
function setColor(){
var index = $(target).timespinner('options').highlight;
var s = '';
$.map(tb.val().split(':'), function(t,i){
s += ':<span t-index="' + i + '"';
if (i == index){
s += ' style="background:blue;color:#fff"';
}
s += '>' + t + '</span>';
});
state.label.html(s.substr(1));
}
function setSelectionRange(target, start, end){
if (target.selectionStart){
target.setSelectionRange(start, end);
} else if (target.createTextRange){
var range = target.createTextRange();
range.collapse();
range.moveEnd('character', end);
range.moveStart('character', start);
range.select();
}
}
function highlight(target, index){
var selections = [[0,2],[3,5],[6,8]];
var opts = $.data(target, 'timespinner').options;
if (index != undefined){
opts.highlight = index;
}
var range = selections[opts.highlight];
if (range){
var tb = $(target).timespinner('textbox');
setSelectionRange(tb[0], range[0], range[1]);
tb.focus();
}
}
});
}
});
Call 'highlightValue' method to highlight the time value.
$('#tt').timespinner('highlightValue');