The main use of settimeout (), recursion and string.substring ();
The effect is like having a typist typing.
1<!doctype html>234<meta charset= "UTF-8" >5<meta name= "Generator" content= "editplus®" >6<meta name= "Author" content= "" >7<meta name= "Keywords" content= "" >8<meta name= "Description" content= "" >9<title>Document</title>Ten One<body bgcolor= "#ccc" onload= "printer ();" > A<H2 align= "center" > Text Auto Output -<br> -<br> the -<br> -<form align= "center" > -<textarea cols= "rows=" "id=" text "style=" Background-color: #FF99CC; Color: #330033; Cursor:default; font-family:arial; font-size:18px "wrap=virtual></textarea> +</form> -</body> +<script type= "Text/javascript" > A at //get TextArea Object - varText=document.getelementbyid ("Text"); - //the content to output - varStr= "The traditional HTML language does not develop interactive dynamic Web pages, but JavaScript does it well. JavaScript is a fairly simple and easy to learn network programming language, through the combination of her and HTML language, to achieve real-time Dynamic Web page effects, which gives web visitors to browse the Web while also providing some fun. "; - varPos=0; - //use recursion and settimeout () to implement text output in functionprinter () { -Text.value=str.substring (0,pos) + "|"; to //determine whether to reach the end. If it is, then one second, then again. + if(pos++>str.length) { -Pos=0; theSetTimeout ("Printer ()", 1000); *}Else{ $SetTimeout ("Printer ()", 50);Panax Notoginseng } - } the</script> +Automate text output with JavaScript