我正在尝试使用 JS 创建 JSON 模板,这是我的代码。由于某种原因,它没有显示任何结果。有人可以检查一下是什么问题
<html>
<head>
<script type="text/javascript"src=""http://jsontemplate.googlecode.com/svn/trunk/javascript/json-template.js"">
</script>
<script type="text/javascript">
function write() {
var t = jsontemplate.Template("{# This is a comment and will be removed from the output.}\n\n{.section products}\n <h2>Products for Dove</h2>\n\n <table width=\"100%\">\n {.repeated section products}\n <tr><td>{Product Name}</td>\n</tr>\n {.end}\n </table>\n{.or}\n <p><em>(No page content matches)</em></p>\n{.end}\n");
var s = t.expand({
"products": [{
"Product Name": "dove moisturiser"
},
{
"Product Name": "Deodrant"
}]
});
document.getElementById("replace").innerHTML = s;
}
</script>
</head>
<body onload="write();">
<h4>This is for test.</h4>
<div id="replace"></div>
</body>
</html>