选择a-z中的随机字母

问题描述:

如何从a-z中选择一个随机字母并将其放在标题中 我的html本身,并使其替换了那里的其他任何字母 前?我不知道我所做的工作是否可行.

How do I choose a random letter from a-z and put it into a heading in my html by itself and make it replace any other letter that was there before? I don't know if what I've done works.

function randLetter( ) {

var letters =
    ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q"
    ,"r","s","t","u","v","w","x","y","z");

var letter = letters[Math.floor(Math.random()*letters.length)];

return letter

}

$('#letter').html('letter')

对于大写字母,您可以使用

For Capital Letters you can use

String.fromCharCode(65+Math.floor(Math.random() * 26))

对于小写字母

String.fromCharCode(97+Math.floor(Math.random() * 26))