开发者

Javascript : code for 2 dropdown box ( Hours : Minutes)

开发者 https://www.devze.com 2023-04-12 21:40 出处:网络
Can anyone help me on how to code in javascript for time which consist of 2 dropdown boxes:- 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号