jquery等价dom操作

发布时间:2019-05-21 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了jquery等价dom操作脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

介绍 jquery 等价于 dom 原生操作。

empty()

$("#id").empty()

VAR el = document.getElementById("app");
var child, nextChild;
for(child = el.FirstChild; child; ) {
    nextChild = child.nextSibling;
    el.removeChild(child);
    child = nextChild;
}

apPEnd()

$("#id").append()

这里的 append 可以使用 reactrender 函数来做

render(
    <div>Hello wolrd</div>,
    document.getElementById("app")
)

css()

$(".tdXMask").css({ display: "none" });

var els = document.getElementsByclassname("tdxmask");
els.foreach(function(el) {
    el.style.display = "none";
})

extend()

$.extend({}, item.hot.style, {"background-image": "none" })

style = Object.assign({}, item.hot.style, {"background-image": "none" });

sibings(), find(), removeClass()

$el.siblings().find("span").removeClass("sortup").removeClass("sortdown")

// 查找某个节点的所有兄弟节点,并返回数组列表
function siblings(el) {
    var s = [];
    var preEl, nextEl;
    preEl = el.previousSibling;
    nextEl = el.nextSibling;

    // 前面的兄弟节点
    while (preEl) {
        s.push(preEl);
        preEl = preEl.previousSibling;
    }

    // 后面的兄弟节点
    while (nextEl) {
        s.push(nextEl);
        nextEl = nextEl.nextSibling;
    }

    return s;
}

// 查询子节点中的某个标签
function findChildNodesByTagName(el, tagName) {
    var s = [];
    var childNodeList = el.childNodes;

    for(var i = 0; i < childNodeList.length; i++) {
        var cnode = childNodeList[i];
        if(cnode.nodeName.toUpperCase() == tagName.toUpperCase()) {
            s.push(cnode);
        }
    }

    return s;
}

let sibs = siblings(el);
sibs.map( sib => {
    findChildNodesByTagName(sib, "span").map( node => {
        // debugger;
        node.className = "";
    })
} )

脚本宝典总结

以上是脚本宝典为你收集整理的jquery等价dom操作全部内容,希望文章能够帮你解决jquery等价dom操作所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。