📜  在 html 元素中逐字母显示字母 - Html 代码示例

📅  最后修改于: 2022-03-11 14:53:11.301000             🧑  作者: Mango

代码示例1
document.addEventListener('DOMContentLoaded', function() {

    showText("#msg", "Hello, World!", 0, 100);

});

let showText = function (target, message, index, interval) {
    if (index < message.length) {
        document.querySelector(target).innerHTML =
            document.querySelector(target).innerHTML + message[index++];
        setTimeout(function () { showText(target, message, index, interval); }, interval);
    }
}