阅读 36

html js jquery web 一个最精简的自动化 table 实例

介绍

  • 1.样式
  • 2.html
  • 3.js添加内容

 

样式 谷歌效果

上代码

<html>
<head>
	<title>New Document</title>
	<meta name="Generator" content="EditPlus">
	<meta name="Author" content="">
	<meta name="Keywords" content="">
	<meta name="Description" content="">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<style>
	body {padding: 100px 0 0 100px;}
	/* text-align*/
	table{text-align:center;}
	/* width  display*/
	table thead{ width: 600px;display:block; }
	/* width height display overflow*/
	table tbody{width: 600px;height: 100px;display:block;overflow: auto;}
	/*width border */
	table tbody tr td{border-bottom:1px solid #000;	width:200px;}
	/* width border */
	table thead tr th{border-bottom:1px solid #000; width:200px; }
	
</style>
<body>
	<!-- 表格去除空隙 -->
	<table border="0" cellpadding="0" cellspacing="0"> 
			<thead></thead>
			<tbody></tbody>
	</table>
</body>  
<script>

//数据替换成自己需要用的数据
var data = [{  "s4": "ss", "s5": "ss", "s6": "ss" },{  "s4": "ss", "s5": "ss", "s6": "ss" }]

//直接把表头和表内全部载入
var addTableF = function (features) {
	var hthead = "";
	var htbody = "";
	hthead += '<tr>';//编写表头
	for (var j in features[0]) {
		hthead += '<th><div>' + j + '</div></th>';
	}
	hthead += '</tr>';
	for (i = 0, len = features.length; i < len; i++) {//编写表格
		htbody += '<tr>';
		for (var j in features[i]) {
			htbody += '<td><div>' + features[i][j] + '</div></td>';
		}
		htbody += '</tr>';
	}
	$("table thead").empty().html(hthead);
	$("table tbody").empty().html(htbody);
}
addTableF(data);
</script>
</html>
复制代码

 

 

ok

 

 

 

持续更新

 

 

 

 

文章分类
后端
文章标签