2、制作好模板、准备好json数据、启动
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>json2html</title> <script type="text/javascript" src="json2html.js"></script> </head> <body> <script type="text/javascript"> //html模板格式 var transform = {‘tag‘:‘p‘,‘html‘:‘${name} (${age})‘}; //json数据 var data = [ {‘name‘:‘Bob‘,‘age‘:40}, {‘name‘:‘Frank‘,‘age‘:15}, {‘name‘:‘Bill‘,‘age‘:65}, {‘name‘:‘Robert‘,‘age‘:24} ]; //启动 document.write(json2html.transform(data,transform)); </script> </body> </html>
输出html代码:
<p>Bob (40)</p> <p>Frank (15)</p> <p>Bill (65)</p> <p>Robert (24)</p>
时间: 2024-10-20 03:12:37