我正在尝试在jQuery中创建类似的东西:
var x = 0;
function start(){
setInterval(function () {return changeText(x++);}, 2000);
}
function changeText(index){
var words = getTextFromDiv().split("/");
var result = "";
for(var i = 0; i < words.length; i++){
if(i == index)
words[i] = "<b>" + words[i] + "</b>";
result += words[i];
if(i != words.length - 1)
result += "/";
}
document.getElementById("divId").innerHTML = result;
if(x == words.length){
x = 0;
}
}
//get text from element without HTML
function getTextFromDiv() {
var element = document.getElementById('divId');
return element.innerText || element.textContent;
}
start();
<div id="divId">
aaa / bbb / ccc / eee
</div>
我尝试使用每个循环和延迟。但它没有用。你知道怎么做吗?