• JS代码片段:appendHTML 和 insertAdjacentHTML


    function appendHTML(container,html,position){
        position =position || 'after';
        var objE = document.createElement("div"),
            nodes=null,
            fragment = document.createDocumentFragment();
        objE.innerHTML = html;
        nodes=objE.childNodes;
        for (var i=0, length=nodes.length; i<length; i++) {
            fragment.appendChild(nodes[0]);
        }
        position !=='before'? container.appendChild(fragment) : container.insertBefore(fragment,container.firstChild);
    
        nodes = null;
        fragment = null;
    
    }
    

     

    insertAdjacentHTML(插入邻近html)

    element.insertAdjacentHTML(position, html);

    position是相对于element元素的位置,并且只能是以下的字符串之一:

    beforebegin
    在 element 元素的前面。
    afterbegin
    在 element 元素的第一个子元素前面。
    beforeend
    在 element 元素的最后一个子元素后面。
    afterend
    在 element 元素的后面。
  • 相关阅读:
    SP338 ROADS
    [Usaco2008 Mar]牛跑步
    [Cerc2005]Knights of the Round Table
    [Poi2005]Piggy Banks小猪存钱罐
    Pku1236 Network of Schools
    PKU2186 Popular Cows 受欢迎的牛
    黑暗城堡
    入门OJ:最短路径树入门
    Sqli-labs
    Sqli-labs
  • 原文地址:https://www.cnblogs.com/yanyd/p/4685989.html
Copyright © 2020-2023  润新知