首页 > 代码库 > js 表格实现

js 表格实现

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>张三疯个人简历</title>
 6 </head>
 7 <body>
 8     <script type="text/javascript">
 9         var name = "张三丰";
10         var sex = true;
11         var age = 34;
12         var edu = "大专";
13         var time = "2005年7月";
14         var school = "北京科技大学";
15 
16         var str = "";
17             str += ‘<table width="500" style="border-collapse:collapse;" border="1" cellspacing="0" cellpadding="2">‘;
18             str += ‘  <tr>‘;
19             str += ‘    <td colspan="4" align="center"><h2><font color="#FF0000">‘+name+‘的个人简介</font></h2></td>‘;
20             str += ‘  </tr>‘;
21             str += ‘  <tr>‘;
22             str += ‘    <td align="right"><b>姓名:</b></td>‘;
23             str += ‘    <td>‘+name+‘</td>‘;
24             str += ‘    <td align="right"><b>性别:</b></td>‘;
25             str += ‘    <td>‘+(sex ? ‘男‘ : "女" )+‘</td>‘;
26             str += ‘  </tr>‘;
27             str += ‘  <tr>‘;
28             str += ‘    <td align="right"><b>年龄:</b></td>‘;
29             str += ‘    <td>‘+age+‘</td>‘;
30             str += ‘    <td align="right"><b>学历:</b></td>‘;
31             str += ‘    <td>‘+edu+‘</td>‘;
32             str += ‘  </tr>‘;
33             str += ‘  <tr>‘;
34             str += ‘    <td align="right"><b>毕业时间:</b></td>‘;
35             str += ‘    <td>‘+time+‘</td>‘;
36             str += ‘    <td align="right"><b>毕业院校:</b></td>‘;
37             str += ‘    <td>‘+school+‘</td>‘;
38             str += ‘  </tr>‘;
39             str += ‘</table>‘;
40         document.write(str);
41     </script>
42 </body>
43 </html>

 

效果图

技术分享

 

js 表格实现