提问者:小点点

如何在JavaScript中制作“类型效果”?


此代码应每200毫秒从字符串mytext中键入一个字母,以类似于类型效果,但它的类型是undefined,而不是letters

null

var myText = "loremloremloremloremloremloremloremloremloremloremloremlorem",
    myButton = document.getElementById("Button"),
    result = document.getElementById("type"),
    i;
myButton.onclick = function (){
    "use strict";
    setInterval(function(){
        result.textContent += myText[i];
        i++;
    }, 200);
}
<p id="type"></p>
    <button  id="Button">Click!</button>

null


共1个答案

匿名用户

缺少i=0,初始值