读书人

【模板】script的type属性替x-tmpl怎

发布时间: 2013-08-14 14:27:55 作者: rapoo

【模板】script的type属性为x-tmpl,怎样分离出这部分代码单独写模板文件
原代码如下:

<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td class="preview"><span class="fade"></span></td>
<td class="name"><span>{%=file.name%}</span></td>
<td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
{% if (file.error) { %}
<td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
{% } else if (o.files.valid && !i) { %}
<td>
<div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
</td>
<td class="start">{% if (!o.options.autoUpload) { %}
<button class="btn">


<i class="icon-upload icon-white"></i>
<span>Start</span>
</button>
{% } %}</td>
{% } else { %}
<td colspan="2"></td>
{% } %}
<td class="cancel">{% if (!i) { %}
<button class="btn red">
<i class="icon-ban-circle icon-white"></i>
<span>Cancel</span>
</button>
{% } %}</td>
</tr>
{% } %}
</script>


由于这部分代码写在html页中实在太多,想要把它们写在单独的文件里,然后引用进来,像写单独的js文件那样,但是不知道具体的应该如何操作。。。。请求大神指教。。。。


另:定义这个模板的文件是一个压缩过的文件。。。这个模板的功能是把要上传的文件加载成一个列表。 动态html模板 模板文件分离
[解决办法]
把你的html模板部分(像我贴的哪样)放到一个js文件中。在你的html模板中引用这个文件,把你拿到的o.files[i]组成一个json 对象传给js文件中函数名

读书人网 >JavaScript

热点推荐