Javascript JSON模板未显示
我正在尝试使用JS创建JSON模板 这是我的代码。出于某种原因,它不会显示任何结果。请有人检查一下问题是什么Javascript JSON模板未显示,javascript,json,Javascript,Json,我正在尝试使用JS创建JSON模板 这是我的代码。出于某种原因,它不会显示任何结果。请有人检查一下问题是什么 <html> <head> <script type="text/javascript"src=""http://jsontemplate.googlecode.com/svn/trunk/javascript/json-template.js""> </script> <script type="te
<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");
}
这是测试用的。
您似乎有一个多行字符串,这在JS的这个表单中是不受支持的。脚本的src
属性也错误(src=“”http://jsontemplate.googlecode.com/svn/trunk/javascript/json-template.js“”
),您只需要在开头和结尾加上引号。看一看。要了解如何调试JavaScript,请查看。获取您的JavaScript代码,打开浏览器以粘贴该代码,然后单击JSHint按钮。我已更正了上述错误。我猜脚本已触发,但未显示JSON。.任何原因.code都会按上述方式更新。它在jsfiddle.net中有效
"products": [{
"Product Name": "dove moisturiser"
},
{
"Product Name": "Deodrant"
}]
});
document.getElementById("replace").innerHTML = s;