현재 시간과 분
by this_mong
HTML
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<select class="hour"></select>시
<select class="minute"></select>분
JavaScript
var html = '';
for (var i = 0; i < 60; i++) {
html += "<option value = '" + i + "' >" + i + "</option>";
}
$('.minute').append(html);
var d = new Date();
var n = d.getMinutes();
$(".minute").val(n);
var htm = '';
for (var j = 0; j < 24; j++) {
htm += "<option value = '" + j + "' >" + j + "</option>";
}
$('.hour').append(htm);
var dt = new Date();
var h = dt.getHours();
$(".hour").val(h);
$(".hour option").filter(function() {
//may want to use $.trim in here
return $(this).text() == h;
}).attr('selected', true);
$(".minute option").filter(function() {
//may want to use $.trim in here
return $(this).text() == n;
}).attr('selected', true);