将数字转换为字母javascript [英] convert number to letter javascript

查看:123
本文介绍了将数字转换为字母javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数字转换为字母.我正在制作需要一个数字或一个数字和字母的div数组.所以1-3只是1-3.但4-13必须是a/4,b/5,c6等.有没有办法我可以轻松地将这些数字转换为字母.也许改变一个设定值的ASCII值?

I'm trying to convert numbers into letters. I'm making an array of divs that either need a number or a number and letter. so 1-3 are just 1-3. but 4-13 need to be a/4, b/5, c6 and so on. is there a way I can converts these numbers into letter easily. maybe changing the ascii values by a set amount?

     for(var i = 1; i < 33; i++){
    if( i < 4 || (i > 13 && i < 20) || i > 29){
        $('#teeth-diagram').append("<div class='tooth' id='" + i + "'>&nbsp;</div>");
    }else{
        $('#teeth-diagram').append("<div class='tooth' id='" + Letter goes here + "/" + i + "'>&nbsp;</div>");
    }
}

推荐答案

由于97是'a'的ascii值,而'a'的值是3,因此您需要执行此操作以获取整数的值转换为字符:

since 97 is the ascii value for 'a', and your value for 'a' is 3, you need to do this to get the value of the integer converted to a character:

if(i>=3){
    String.fromCharCode(94 + i);
}

这篇关于将数字转换为字母javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆