-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex4.html
66 lines (60 loc) · 1.62 KB
/
ex4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<html>
<head>
<title>htmltmpl usage example</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="htmltmpl/core.js"></script>
<script type="text/javascript" src="htmltmpl/func.js"></script>
<script type="text/javascript">
var tmpl; // make tmpl a global var for debug purposes
function add()
{
var el;
tmpl = new htmltmpl(document.getElementById("tbody_tmpl"),
{ ret_dom: 1 });
tmpl.funcs.echo = function (separator) {
var i, out = "";
var str = this.get_data("text");
var count = this.get_data("count");
for(i = 0; i < count; i++)
if ( i )
out += separator + str;
else
out += str;
return out;
};
el = tmpl.apply({ text: document.getElementById("text").value,
count: document.getElementById("count").value });
document.getElementById("cntr").appendChild(el);
}
</script>
</head>
<body>
<div id="tbody_tmpl" style="display: none">
<!--<tbody>
<tr>
<td>text/count:</td>
<td>{%TMPL_VAR NAME=text%}/{%TMPL_VAR NAME=count%}</td>
</tr>
<tr>
<td>result:</td>
<td>{%TMPL_FUNC NAME=echo ARGS=[" | "]%}</td>
</tr>
</tbody>-->
</div>
<table>
<tbody>
<tr>
<td>text:</td>
<td><input type="text" id="text" value=""/></td>
</tr>
<tr>
<td>count:</td>
<td><input type="text" id="count" value=""/></td>
</tr>
</tbody>
</table>
<input type="button" onclick="add()" value="add"/>
<table id="cntr">
</table>
</body>
</html>