【发布时间】:2021-12-31 01:42:00
【问题描述】:
var i = 0;
var txt = 'Christmas Family Service - Sunday 19th December at 11:45 am. Come along to Bethany Evangelical Church and find out about the real meaning of Christmas.'; /* The text */
var speed = 50; /* The speed/duration of the effect in milliseconds */
function typeWriter() {
if (i < txt.length) {
document.getElementById("demo").innerHTML += txt.charAt(i);
i++;
setTimeout(typeWriter, speed);
}
}
<div class="announce">
<p id="demo">
<script>
document.write(typeWriter());
</script>
</p>
</div>
Cundefined 圣诞节家庭服务 - 12 月 19 日星期日上午 11:45。一起来伯大尼福音教会,了解圣诞节的真正意义。
【问题讨论】:
-
当您执行
document.write时,它会将参数添加到文档中。在您的情况下,typeWriter()的结果是undefined(因为typeWriter不返回任何内容)
标签: javascript html output undefined