javascript 循环显示<hn>字体
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>使用匿名函数</title> <script type="text/javascript"> var showFun=function (acount){ for(var i=1;i<=acount;i++){ document.write("<h"+i+">Hello world</h"+i+">"); } } </script> </head> <body> <input type="button" value="点击我" onclick="showFun(6)"> </body> </html>
上面这种方法是使用javascript的匿名函数进行显示,也可以直接循环显示(下面)
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <html> 3 <head> 4 <title> hello world </title> 5 <script type="text/javascript"> 6 function show(){ 7 document.write("使用JavaScript脚本循环输出helloworld"); 8 9 for(var i=1;i<=6;i++){ 10 document.write("<h"+i+">hello world</h"+i+">"); 11 } 12 } 13 </script> 14 </head> 15 <body> 16 <from > 17 <input type="button" value="点击我" onclick="show()"> 18 </from> 19 </body> 20 </html>