无闪烁更新网页内容JS实现


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


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3