我想在html文档中的脚本标记中记录注释。我怎么能这样做?
<!DOCTYPE html>
<html>
<body>
<script>
//my comment
var test = "some js";
/* start of comment
...
end of comment*/
</script>
<!-- This is a comment -->
<p>This is a paragraph.</p>
</body>
</html>
现在,我有这段代码来获取所有HTML注释
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
jQuery.noConflict();
$(function() {
$("*").contents().filter(function(){
return this.nodeType == 8;
}).each(function(i, e){
console.log(e.nodeValue);
});
});
将返回:这是评论