且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取HTML评论标记内的文字?

更新时间:2023-12-05 21:40:58

不使用正则表达式解析HTML 。你可以使用以下代码:

Please never use regex to parse HTML. You can use the following instead:

var div = $("<div>").html(load_types),
    comment = div.contents().filter(function() {
        return this.nodeType === 8;
    }).get(0);

console.log(comment.nodeValue);

DEMO: http://jsfiddle.net/HHtW7/