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