1.替换两个node:
function replaceEach(aNode, bNode) {
    var aParent = aNode.parentNode;
    var bParent = bNode.parentNode;

    if (aParent && bParent){
        var aNode2 = aNode.cloneNode(true);
        bParent.replaceChild(aNode2, bNode);
        aParent.replaceChild(bNode, aNode);
    }
}
2.自定义insertAfter方法:
function insertAfter(newNode, refNode) {
    var parentNode = refNode.parentNode;
    if (parentNode){
        if (refNode == parentNode.lastChild) {
            parentNode.appendChild(newNode);
        } else {
            parentNode.insertBefore(newNode, refNode.nextSibling);
        }
    }
}

 3.除去文本两边的空格:

var reg = /^\s*|\s*$/g;
textContent = textContent.replace(reg, "");

 

posted on 2018-05-09 16:48  超级蛋蛋饭  阅读(82)  评论(0编辑  收藏  举报