[英]mustache.js is not working
I am trying to learn mustache js but the basic page does not work. 我正在尝试学习髭js,但基本页面无法正常工作。 I was following the http://iviewsource.com/codingtutorials/introduction-to-javascript-templating-with-mustache-js/ but it is out of the date.
我一直在关注http://iviewsource.com/codingtutorials/introduction-to-javascript-templating-with-mustache-js/,但是它已经过时了。 (Currently the basic html doesn't work. In the future I would like to use get JSON in script to get data from json files.) Am I missing anything?
(当前基本的html不起作用。将来,我想在脚本中使用get JSON从json文件中获取数据。)我是否缺少任何内容?
<!DOCTYPE <!DOCTYPE html>
<html lang='en'>
<head>
<meta charset="utf-8"/>
<title>messages</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js">
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js">
</script>
</head>
<body onload="loadUser()">
<div id="target">Loading...</div>
<script id="template" type="x-tmpl-mustache">
Hello {{ subject }}!
</script>
<script>
function loadUser() {
var template = $('#template').html();
Mustache.parse(template); // optional, speeds up future uses
var rendered = Mustache.render(template, {subject: "Luke"});
$('#target').html(rendered);
}
});
</script>
</body>
</html>
Syntax error. 语法错误。 Remove extra brackets at the bottom (commented out in the code below).
卸下底部的多余支架(在下面的代码中作了注释)。
<!DOCTYPE html> <html lang='en'> <head> <meta charset="utf-8"/> <title>messages</title> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"> </script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js"> </script> </head> <body onload="loadUser()"> <div id="target">Loading...</div> <script id="template" type="x-tmpl-mustache"> Hello {{ subject }}! </script> <script> function loadUser() { var template = $('#template').html(); Mustache.parse(template); // optional, speeds up future uses var rendered = Mustache.render(template, {subject: "Luke"}); $('#target').html(rendered); } // }); <-- here </script> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.