Home > Web Front-end > JS Tutorial > An example of using template engine in js (code)

An example of using template engine in js (code)

不言
Release: 2018-08-13 16:21:51
Original
2437 people have browsed it

This article brings you an example (code) of using template engine in js. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>basic-demo</title>
<script src="template-web.js"></script>
</head>
<body>
<p id="content"></p>
<script id="test" type="text/html">
{{if isAdmin}}
<h1>{{title}}</h1>
<ul>
 {{each list as value i}}
  <li>索引 {{i + 1}} :{{value}}</li>
 {{/each}}
</ul>
{{/if}}
</script>
<script>
var data = {
 title: &#39;基本例子&#39;,
 isAdmin: true,
 list: [&#39;文艺&#39;, &#39;博客&#39;, &#39;摄影&#39;, &#39;电影&#39;, &#39;民谣&#39;, &#39;旅行&#39;, &#39;吉他&#39;]
};
var html = template(&#39;test&#39;, data);
document.getElementById(&#39;content&#39;).innerHTML = html;
</script>
</body>
</html>
Copy after login

Related recommendations:

Use js attributes to achieve the effect of horizontal drop-down menu in html5 (code)

multiparty implementation file in nodejs Uploaded code example

The above is the detailed content of An example of using template engine in js (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template