is there a way to append leading zero's to an ordered number list? (01 or 001 as opposed to just 1)

后端 未结 3 2076
谎友^
谎友^ 2021-01-03 22:27

by default when you use the

    tag to create an ordered list you get something like:

    1. . . 10. . . 100

    ...but is there a way to change

3条回答
  •  执笔经年
    2021-01-03 22:50

    You need to use JavaScript for this.

    function addzeros(number, length) {
        var num = '' + number;
        while (num.length < length) {
            num = '0' + num;
        }
        return num;
    }
    
    alert(addzeros(100, 5))
    

    Example usage
    addzeros(1,3) will give you 001
    addzeros(10,3) will give you 010
    addzeros(100,0) will give you 100
    addzeros(100,6) will give you 000100

    Check working example at http://jsfiddle.net/ED8Hj/

提交回复
热议问题