打字机效果的消息

  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript">
  5. message="最好的学习方法,是学习实例。-www.jishuchi.com"
  6. pos=0
  7. maxlength=message.length+1
  8.  
  9. function writemsg()
  10. {
  11. if (pos<maxlength)
  12. {
  13. txt=message.substring(pos,0)
  14. document.forms[0].msgfield.value=txt
  15. pos++
  16. timer=setTimeout("writemsg()", 50)
  17. }
  18. }
  19. function stoptimer()
  20. {
  21. clearTimeout(timer)
  22. }
  23. </script>
  24. </head>
  25.  
  26. <body onload="writemsg()" onunload="stoptimer()">
  27. <form>
  28. <input id="msgfield" size="65">
  29. </form>
  30. </body>
  31. </html>