用jQuery选择HTML注释 [英] Selecting HTML comments with jQuery

查看:73
本文介绍了用jQuery选择HTML注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道如何使用jQuery选择HTML注释节点?

 < html> 
< head>
< title>检查测试< /标题>
将脚本类型= 文本/ JavaScript的 SRC = http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js >< /脚本>
< script type =text / javascript>
$(function(){
$(body *)。each(function(){
alert($(this).wrap(< span />) .parent()。html());
});
});
< / script>
< / head>
< body>
<! - Hello - >>
< p>
< label for =thing> Thing Label< / label>
< input id =thingtype =checkbox/>
< / p>




我不接受评论。 jQuery comments()插件,它会为您做到这一点。用法:

  var comments = $(#foo).comments(); 
alert(comments.html());


Does any one know how to select HTML comment nodes with jQuery?

<html>
<head>
    <title>Check Test</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $("body *").each(function() {
                alert($(this).wrap("<span />").parent().html());
            });
        });
    </script>
</head>
<body>
    <!-- Hello -->  
    <p>
        <label for="thing">Thing Label</label>
        <input id="thing" type="checkbox" />
    </p>

This doesn't pick up the comment.

解决方案

There's the jQuery comments() plugin which will do that for you. Usage:

var comments = $( "#foo" ).comments();
alert(comments.html());

这篇关于用jQuery选择HTML注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆