[javascript]逐个打印文字

<html>
<head>
<title></title>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
</head>
<body onload="setInterval(trim,200)" bgcolor="black">
<p id="exp" style="font-family:黑体;color:blue;">
</p>
<script>
var exp=document.getElementById("exp");
var str="无尽的孤独<br /><br />无尽的守候";
y=1;
function trim()
{
    var trimstr = str.substring(0,y);
    exp.innerHTML = trimstr;
    if(y<str.length)y++;
    else clearInterval(setInterval(trim,200));
}
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/co1d7urt/p/2963396.html