【发布时间】:2016-05-08 03:17:48
【问题描述】:
本质上,这个函数应该做的是从输入文本中获取单词列表,并从下拉菜单中以客户选择的间隔 (WPM) 将其设置在显示器上。
如果函数中传递的单词包含问号、句点、冒号、分号、感叹号或逗号,则将其删除,并将所选间隔加倍。例如,如果单词之间的延迟是 117 毫秒,那么它将是 234 毫秒。
我很难确定您确定传递的单词是否包含标点符号并将其删除的部分。
我收到一个错误: 未捕获的类型错误:无法读取未定义的属性“indexOf”。
我不确定为什么会这样,因为 list[index++] 是 String 而 indexOf 是 Javascript 中的字符串方法,而不是属性。
我也不确定如何实施延迟。鉴于我以这种方式使用了setInterval()(并且我只能为此目的使用 setInterval),我不确定如何在显示中设置String 两次,同时还包括延迟.
function runDisplay(data, id) {
var reader = document.getElementById(id);
var index = 0;
if (timer) {
clearInterval(timer);
}
if (data.length) {
timer = setInterval(function() {
var punctuation = [".", ",", ":", ";", "!", "?"];
var textSpeed = 117; // default
for (var j = 0; j < punctuation.length; j++) {
// remove punctuation if found and double text delay
// if multiple found, remove only one
if (!(data[index++].indexOf(punctuation[j]) === -1)) {
data[index++] = string.replace(punctuation[j], '');
// set data[index++] to display twice to double delay?
}
}
reader.innerHTML = data[index++];
index = index % data.length;
}, textSpeed);
}
}
【问题讨论】:
标签: javascript string character contains intervals