网络编程
位置:首页>> 网络编程>> JavaScript>> 无闪烁更新网页内容JS实现

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

  发布时间:2024-05-09 10:37:18 

标签:无闪烁,更新网页内容

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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com