使用JS脚本在html页面上编写“交互式及时”文本

时间:2013-11-08 19:39:43

标签: javascript

我正在尝试制作一个能在html页面上自动编写“及时”文本的Javascript。作为一个例子,我希望它写“Hello world”,但每隔一秒写一个字母。

如果您了解我可以查看的此类代码的任何示例,我将非常高兴。

谢谢。

1 个答案:

答案 0 :(得分:1)

试试这个:

var index = 0;
var hello = "hello world";
function write()
{
    document.write(hello.substr(index,1));
    index++;
    if(index >= hello.length)
    {
        clearInterval(i);
    }
}
setInterval(write, 1000);