What is a method that can be used to increment letters?

前端 未结 14 2745
我在风中等你
我在风中等你 2020-11-27 04:19

Does anyone know of a Javascript library (e.g. underscore, jQuery, MooTools, etc.) that offers a method of incrementing a letter?

I would like to be able to do somet

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 04:31

    You can try this

    console.log( 'a'.charCodeAt​(0))​
    

    First convert it to Ascii number .. Increment it .. then convert from Ascii to char..

    var nex = 'a'.charCodeAt(0);
    console.log(nex)
    $('#btn1').on('click', function() {
       var curr = String.fromCharCode(nex++)
       console.log(curr)
    });
    

    ​Check FIDDLE

提交回复
热议问题