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

标签 jquery html

<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/

相关文章:

jquery - jQuery 和 Google Maps API v3 的最佳插件?

jquery - CORS,在 Chrome v36 中工作,在 Chrome v37 中失败

html - 添加拉伸(stretch)图像作为 div/站点背景

javascript - 使用 Jquery 更改动态生成的 html 中的值

html - 带有显示内联 block 的 Div

javascript - jQuery 滚动到可滚动 div 中元素的顶部卡住循环

javascript - clearTimeout 似乎没有清除全局定义的计时器 ID

javascript - 检查鼠标输入的元素内容

javascript - 在 asp.net c# 中运行时添加多个 js 文件

javascript - 我可以向 html 元素添加自定义属性吗?