作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经找到了用于加载外部模板的引擎,插件和函数,但是我想知道是否有更简单的方法来做到这一点。像这样吗
templates.html
<script id="testTemplate" type="text/html">
<div>this is a div</div>
</script>
<div id="templateContainer"></div>
<script>
$(document).ready(function() {
$("#templateContainer").load("templates.html");
}
</script>
最佳答案
这是我用来加载包含模板集合的模板文件的方法:
var loadTemplateCollection = function(file, success) {
$.get('templates/' + file + '.html', function(templates) {
$('body').append('<div style="display:none">' + templates + '<\/div>');
success();
});
};
self.loadPage = function () {
if (!self.isLoaded()) {
loadTemplateCollection('uploadwizard', function() {
self.isLoaded(true);
self.uploadWizard();
});
}
}
if
很重要):
<div data-bind="template: {'if': isLoaded, name: 'uploadwizard', data: wizard}"></div>
关于templates - 从外部文件加载基因 knockout 模板,而无需复杂的引擎?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17073648/
我是一名优秀的程序员,十分优秀!