js 元素Dom新建并插入页面createElement

纯js

var o = document.createElement('script');
o.type = 'text/template';
o.id = 'demo';
document.documentElement.childNodes[0].appendChild(o);

jquery

$("<script type='text/template'>").attr('id', id + '_template').appendTo("body").load(url, function (tpl) {
  cb(tpl);
});
原文地址:https://www.cnblogs.com/CyLee/p/7839648.html