提高對大度的回答,讓時間範圍內的「平民化的時候,」有一個12小時制的AM和PM名稱。這裏是一個JSFIDDLE
*更新 - 我稍微改變了代碼,以便最小值顯示爲「12:00 AM」,最大值顯示爲「11:59 PM」。小提琴也被更新...
$("#slider-range").slider({
range: true,
min: 0,
max: 1440,
step: 15,
values: [ 600, 720 ], //or whatever default time you want
slide: function(e, ui) {
var hours1 = Math.floor(ui.values[0]/60);
var minutes1 = ui.values[0] - (hours1 * 60);
if(hours1.length == 1) hours1 = '0' + hours1;
if(minutes1.length == 1) minutes1 = '0' + minutes1;
if(minutes1 == 0) minutes1 = '00';
if(hours1 >= 12){
if (hours1 == 12){
hours1 = hours1;
minutes1 = minutes1 + " PM";
}
else{
hours1 = hours1 - 12;
minutes1 = minutes1 + " PM";
}
}
else{
hours1 = hours1;
minutes1 = minutes1 + " AM";
}
if (hours1 == 0){
hours1 = 12;
minutes1 = minutes1;
}
$('.slider-time').html(hours1+':'+minutes1);
var hours2 = Math.floor(ui.values[1]/60);
var minutes2 = ui.values[1] - (hours2 * 60);
if(hours2.length == 1) hours2 = '0' + hours2;
if(minutes2.length == 1) minutes2 = '0' + minutes2;
if(minutes2 == 0) minutes2 = '00';
if(hours2 >= 12){
if (hours2 == 12){
hours2 = hours2;
minutes2 = minutes2 + " PM";
}
else if (hours2 == 24){
hours2 = 11;
minutes2 = "59 PM";
}
else{
hours2 = hours2 - 12;
minutes2 = minutes2 + " PM";
}
}
else{
hours2 = hours2;
minutes2 = minutes2 + " AM";
}
$('.slider-time2').html(hours2+':'+minutes2);
}
});
嗨它的工作很好..非常感謝你.. 注意:hours.length沒有工作4我。我使用hours.toString()。length – 2010-02-17 10:46:37
非常有用....謝謝 – RajeshKdev 2012-03-07 12:01:17
非常好,謝謝 – Kevin 2013-07-08 20:13:36