纯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); });