gpt4 book ai didi

jquery - 展开此代码以检查 head 中的 HTML 注释是否包含字符串

转载 作者:行者123 更新时间:2023-12-01 07:16:34 25 4
gpt4 key购买 nike

<head>包含:

<!-- Foo 1.2.3 by Author Bill -->
<!-- Foo 1.2.3 by Author Joe -->

我只能通过一些可能是错误的代码来达到此目的:

var hc = $('head')[0].childNodes;
for (var i = 0; i < hc.length; i++) {

console.log(hc);

if (hc[i].nodeType == 8) { // comments have a nodeType of 8

// need something here to get a value and verify that one of the comments includes "Bill"
}
}

最佳答案

我认为这可能适合你:

if (hc[i].nodeType == 8) { // comments have a nodeType of 8

var val = hc[i].nodeValue;
if(val.indexOf("Bill") != -1){
//Add glorious code!
}
}

关于jquery - 展开此代码以检查 head 中的 HTML 注释是否包含字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18255107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com