最近在CSDN上有人问,怎么用JS循环26个英文字母,想都没想,写下以下代码
<script type="text/javascript">
<!--
var character = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","X","Y","Z");
for(var i=0;i<25;i++)
{
alert(character[i]);
}
// -->
</script>
后来又看到有另外的解答,很不错,比我的方法巧妙多了,特记录之~~
<script type="text/javascript">
<!--
for(var i=0;i<25;i++)
{
alert(String.fromCharCode((65+i)));
}
// -->
</script>