- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>傻了吧唧地分離了一下</title>
- </head>
- <body>
- <div id="my-list"></div>
- <script type="text/js-tmpl" id="my-list-tmpl">
- <ul>
- <li>{$foo}</li>
- <li>{$baz}</li>
- <li>c</li>
- </ul>
- </script>
- <script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- var tmpl = $('#my-list-tmpl').html();
- var data = {foo: 'bar', baz: 10};
- for(name in data) {
- tmpltmpl = tmpl.replace('{$' + name + '}', data[name]);
- }
- $('#my-list').html(tmpl);
- </script>
- </body>
- </html>