如何使用Javascript处理每个文本字母? [英] How can I process each letter of text using Javascript?
本文介绍了如何使用Javascript处理每个文本字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提醒一个字符串的每个字母,但我不确定如何做到这一点。
I would like to alert each individual letter of a string, but I am unsure how to do this.
所以,如果我有:
var str = 'This is my string';
我希望能够分别提醒T,h,i,s等。这是只是我正在开发的一个想法的开头,但我需要知道如何分别处理每个字母。
I would like to be able to separately alert T, h, i, s, etc. This is just the beginning of an idea that I am working on, but I need to know how to process each letter separately.
我想使用jQuery并且认为我可能需要在测试字符串的长度后使用split函数。
I want to use jQuery and was thinking I might need to use the split function after testing what the length of the string is.
想法?
推荐答案
如果提醒的顺序很重要,请使用:
If the order of alerts matters, use this:
for (var i = 0; i < str.length; i++) {
alert(str.charAt(i));
}
如果警报顺序无关紧要,请使用:
If the order of alerts doesn't matter, use this:
var i = str.length;
while (i--) {
alert(str.charAt(i));
}
这篇关于如何使用Javascript处理每个文本字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文