Javascript : code for 2 dropdown box ( Hours : Minutes)
Can anyone help me on how to code in javascript for time which consist of 2 dropdown boxes:-
Hours : Minutes
There will be 0-12 list for Hours dropdown box
an开发者_如何学运维d 0-59 list for Minutes dropdown box.
Thank you..
http://jsfiddle.net/AyJKM/1/
function buildTimePicker() {
var result = document.createElement('span');
var hours = document.createElement('select');
hours.setAttribute('id', 'hour');
for (var h=1; h<13; h++) {
var option = document.createElement('option');
option.setAttribute('value', h);
option.appendChild(document.createTextNode(h + 'h'));
hours.appendChild(option);
}
var minutes = document.createElement('select');
minutes.setAttribute('id', 'minute');
for (var m=0; m<60; m++) {
var option = document.createElement('option');
option.setAttribute('value', m);
option.appendChild(document.createTextNode(m + 'm'));
minutes.appendChild(option);
}
result.appendChild(hours);
result.appendChild(document.createTextNode(" : "));
result.appendChild(minutes);
return result;
}
window.onload = function() {
document.body.appendChild(buildTimePicker());
}
Edit: added the value attributes.
精彩评论