JavaScript type="text/x-tmpl" 这个是什么意思?

scott · May 07, 2012 · Last by cyqsdy replied at July 17, 2013 · 20507 hits

这中 script 的 type 是什么东东?

script id="template-download" type="text/x-tmpl"> {% for (var i=0, file; file=o.files[i]; i++) { %}

{% if (file.error) { %} {%=file.name%} {%=o.formatFileSize(file.size)%} {%=locale.fileupload.error%} {%=locale.fileupload.errors[file.error] || file.error%} {% } else { %} {% if (file.thumbnail_url) { %} {% } %} {% } %} {% } %} script>

Handlebars template 吧

JQuery Template

script 标签的 type 写成这个,浏览器会认为他不是 javascript 脚本,从而不去解析执行里面的内容 其实这是一种很无奈的做法,因为 JS 语法中没有类似 ruby 这样的 here doc

新手刚用 jq file uploader,有类似代码 http://stackoverflow.com/questions/10025856/what-is-x-tmpl 有类似得问题

You need to Sign in before reply, if you don't have an account, please Sign up first.