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

 

posted @ 2017-11-15 16:31  贝尔塔猫  阅读(1229)  评论(0编辑  收藏  举报