开发者

jquery - single digit numbers should start with 0

Hi I am wondering is there anyway to make a single digit number ie:1 become 01

This is the code I using at the moment but all the single digits are only coming out as single digits

 setTimeout(function() {
                            if(a == "hh")
                            {
                                var minOffset = 01, maxOffset = 12;
                            }
                            else
                            {
                                var minOffset = 01, maxOffset = 60;
                            }

                            var timeSelector = $('select[name='+a+']');
                            var thisYear = new Date().getFullYear();
                            //var select = $('<select name="year" id="yyyy" class="formbox dobselect">');

                            for (var i = minOffset; i <= maxOffset; i++) {
                                var time = i;
               开发者_如何学JAVA                 $('<option></option>')
                                .attr('label', time)
                                .attr('value', time)
                                .html(time)
                                .appendTo(timeSelector);
                            }


                        },900); 


Here's an example that demonstrates what I think you're after:

var tstr = "";
if(time <10)
{
    tstr = "0";
}
tstr += time;

Then put tstr wherever you want to display it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜