You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
585 B
27 lines
585 B
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>compile-demo</title>
|
|
<script src="../../dist/template-native.js"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>在javascript中存放模板</h1>
|
|
<div id="content"></div>
|
|
<script>
|
|
var source = '<ul>'
|
|
+ '<% for (var i = 0; i < list.length; i ++) { %>'
|
|
+ '<li>索引 <%= i + 1 %> :<%= list[i] %></li>'
|
|
+ '<% } %>'
|
|
+ '</ul>';
|
|
|
|
var render = template.compile(source);
|
|
var html = render({
|
|
list: ['摄影', '电影', '民谣', '旅行', '吉他']
|
|
});
|
|
|
|
document.getElementById('content').innerHTML = html;
|
|
</script>
|
|
</body>
|
|
</html> |