todo list
无闪烁更新网页的课题比较大。
加载的html字符串(通过ajax获取的),如果还需要运行代码,那么肯定有问题。
希望用一个不显示的iframe来承载这个对象。这有点dirty work的感觉。
最终解决方案是
var str2DOMElement = function(html) {
var frame = document.createElement(\'iframe\');
frame.style.display = \'none\';
document.body.appendChild(frame);
frame.contentDocument.open();
frame.contentDocument.write(html);
frame.contentDocument.close();
var el = frame.contentDocument.body.firstChild;
document.body.removeChild(frame);
return el;
}
var markup = \'<div><p>text here</p></div>\';
var el = str2DOMElement(markup);
本文地址:https://www.stayed.cn/item/3739
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我