有没有办法访问通过
HTML< head>加载的胡子模板文件的内容?通过
JavaScript?
<link rel="template" href="templates/address.mustache" type="text/html" />
要么
<script src="templates/address_field.mustache" type="text/html" charset="utf-8" id="address_template"></script>
我已成功通过ajax和< script>加载它们.身体中的标签,但我不知道如何通过头部作为单独的文件加载文件源.
解决方法
你需要获取方法来捕获模板值外部模板:下面的代码只能在html页面内部工作:
var tmpl=$.trim($('#address_template').val()); //trim the white spaces in the template
Mustache.to_html(TMPL,JSON);
你需要以下代码:“$.get(‘template.html’,”是你的答案.你应该首先加载你的模板:
<!DOCTYPE html>
标题
<script> $(function() { $.getJSON('/data/speakers.json',function(data) { //var template = $('#speakers-template').html(); // console.log(template); // var info = Mustache.render(template,data); // $('#talktitles').html(info);
$.get(‘template.html’,function(template,textStatus,jqXhr){
var info = Mustache.render($(template).filter(‘#speakers-template’).html(),data);
$( ‘#talktitles’)HTML(信息);
});
}); }); </script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。