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