【发布时间】:2016-12-13 08:38:38
【问题描述】:
index = 0;
string1 = '1,2,3,4,5,6,8,9,0#';
string2 = '1,2,3#';
do{
document.write(string1.charAt(index));
index++;
}
while(string1.charAt(index) != '#');
index = 0;
document.write('<br />');
do{
document.write(string2.charAt(index));
index++;
}
while(string2.charAt(index) != '#');
你好,我被困在一个 Javascript 任务中,我需要在一个 do-while 循环中显示上面的字符串,我必须使用 charAt 来这样做。我需要循环在# 符号处停止。但是charAt方法只显示一个数字,
所以我的问题是:我怎样才能用 charAt 显示所有数字?当 # 符号等于 # 符号时,我如何停止我的 do-while 循环
【问题讨论】:
-
你能告诉我们你到目前为止做了什么吗?一个jsfiddle也会很好。我们不会为你工作。如果你不尝试,你将一无所获。
-
我的读心能力说你忘了增加循环内的
index。或者您实际上并没有使用index作为charAt的参数
标签: javascript loops do-while charat