Home  >  Article  >  Web Front-end  >  How to output json to table

How to output json to table

一个新手
一个新手Original
2017-09-08 13:15:471768browse

I have been writing front-end recently. No matter how big or small you are, please come and add some knowledge to my blog.

Not much to say, it is actually a simple js for loop

js code:

$(function(){
	var str=[{name:"zy",age:111,sex:0,pass:1},{name:"zay",age:112},{name:"zby",age:113},{name:"zcy",age:114}];
	obj=eval(str);
	  var ht = '';
	  for(var i=0;i<obj.length;i++){/
	    ht = ht+&#39;<tr>&#39;;
	    ht = ht + &#39;<td>&#39; + obj[i].name + &#39;</td>&#39;;
	    ht = ht + &#39;<td>&#39; + obj[i].age + &#39;</td>&#39;;
	    ht = ht + &#39;<td>&#39; + obj[i].sex + &#39;</td>&#39;;
	    ht = ht + &#39;<td>&#39; + obj[i].pass + &#39;</td>&#39;;
	    ht = ht+&#39;</tr>&#39;;
	  }
	  $(&#39;#tb&#39;).append(ht);
})

html code

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>表格</title>
		<link rel="stylesheet" href="css/table.css" />
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/table.js"></script>
	</head>
	<body>
		<p>
			<table id="tb" >
				<tr>
					<td>1</td>
					<td>1</td>
					<td>1</td>
				</tr>
			</table>
		</p>
	</body>
</html>

The above is the detailed content of How to output json to table. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is closureNext article:What is closure