现在的位置: 首页 > 综合 > 正文

Javascript输出表格

2018年04月09日 ⁄ 综合 ⁄ 共 1282字 ⁄ 字号 评论关闭
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  2. <html xmlns="http://www.w3.org/1999/xhtml"> 
  3. <head> 
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
  5. <script language="JavaScript" type="text/javascript"> 
  6.  
  7.         function addnew() 
  8.         { 
  9.               c   =   prompt("请输入内容!","");//列   
  10.               if   (c   ==   null)    
  11.               {    
  12.                   return false;  
  13.               }    
  14.               else   if   (c.replace(/^\s+|\s+$/g,"")   ==   "")    
  15.               { 
  16.                 alert("输入内容为空!");    
  17.                  return false; 
  18.               } 
  19.               //alert(c); 
  20.         } 
  21.         addnew(); 
  22.  
  23.         var r; //定义行 
  24.  
  25.         setrc(3,c);  //调用指定行列输出表格,根据内容数组维来指定几行几列 
  26.  
  27.         function setrc(r,c){   //指定行列输出表格函数 
  28.         document.write("<table border=1 >") 
  29.         for(i=1;i<=r;i++) 
  30.         { 
  31.             document.write("<tr>")        
  32.             for(j=1;j<=c;j++) 
  33.                 document.write("<td>"+Math.pow(j,i))  //输出数组 
  34.             document.write("</tr>") 
  35.         } 
  36.         document.write("</table>") 
  37.  
  38. //setrc(3,2); 
  39. </script> 
  40. </body> 
  41.  
  42.  
  43. <title>无标题文档</title> 
  44. </head> 
  45.  
  46. <body> 
  47. </body> 
  48. </html> 
  49.  

 

本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/813003

抱歉!评论已关闭.