📅  最后修改于: 2022-03-11 15:04:26.685000             🧑  作者: Mango
function populate(selector) {
var select = $(selector);
var hours, minutes, ampm;
for(var i = 420; i <= 1320; i += 15){
hours = Math.floor(i / 60);
minutes = i % 60;
if (minutes < 10){
minutes = '0' + minutes; // adding leading zero
}
ampm = hours % 24 < 12 ? 'AM' : 'PM';
hours = hours % 12;
if (hours === 0){
hours = 12;
}
select.append($('')
.attr('value', i)
.text(hours + ':' + minutes + ' ' + ampm));
}
}
populate('#timeSelect'); // use selector for your select