使用Javascript更改文本动画
我正在尝试每3秒钟创建一个变化的文本。但它似乎只运行了一次,然后就停止了任何操作。我的代码: HTML使用Javascript更改文本动画,javascript,loops,setinterval,Javascript,Loops,Setinterval,我正在尝试每3秒钟创建一个变化的文本。但它似乎只运行了一次,然后就停止了任何操作。我的代码: HTML <div class="output"> <h2>True Multi-Purpose Theme for <span class="changingtext">Business</span> and More </h2> </div>
<div class="output">
<h2>True Multi-Purpose Theme for
<span class="changingtext">Business</span>
and More
</h2>
</div>
问题是,您在
if
中使用的是赋值而不是比较
错误
if(newText.innerHTML = 'Business'){
正确
if (newText.innerHTML === 'Business') {
let newText=document.querySelector(“.changingtext”)
setInterval(函数(){
如果(newText.innerHTML==='Business'){
newText.innerHTML='Agencies';
}else if(newText.innerHTML==“代理”){
newText.innerHTML='Startups'
}否则{
newText.innerHTML='Business'
}
},3000)
真正的多用途主题
对于
商业及其他
问题在于,您在if
中使用的是分配而不是比较
错误
if(newText.innerHTML = 'Business'){
正确
if (newText.innerHTML === 'Business') {
let newText=document.querySelector(“.changingtext”)
setInterval(函数(){
如果(newText.innerHTML==='Business'){
newText.innerHTML='Agencies';
}else if(newText.innerHTML==“代理”){
newText.innerHTML='Startups'
}否则{
newText.innerHTML='Business'
}
},3000)
真正的多用途主题
对于
商业及其他