标签搜索

目 录CONTENT

文章目录

基于JQuery把注释标签转为文本标签

陈铭
2024-03-30 / 0 评论 / 0 点赞 / 25 阅读 / 150 字 / 正在检测是否收录...
let rows = $(".row").find(".colVideoList");
for (let i = 0; i < rows.length; i++) {
    let chilren = $(rows[i]);
    let title = chilren.find("a")[1].innerHTML;
    // 获取注释节点
    let author_comment_node = $($(chilren.find(".video-elem")[0]).find(".d-inline-block")[0]).contents().filter(function() {
        return this.nodeType === 8; // 8 表示注释节点
    })[0];
    // 替换注释节点
    let author = author_comment_node.nodeValue;
    author = author.substring(author.indexOf("kwokman"));
    author = author.substring(9);
    author = author.substring(0, author.indexOf("</a>"));
    var newText = document.createElement("span");
    newText.textContent = author;
    newText.setAttribute("id", "author");
    author_comment_node.parentNode.replaceChild(newText, author_comment_node);

    var isHide = false;
    for (let word of words3d) {
        if (title.indexOf(word)!=-1){
            chilren.hide()
            isHide = true;
            break
        }
    }
}
0

评论区