【问题标题】:jQuery wrap with html comment tags带有 html 注释标签的 jQuery 换行
【发布时间】:2014-11-12 08:39:51
【问题描述】:

我已经尝试了 3 种解决方案,但都没有成功。

我想用评论标签包裹我的侧边栏。

第一个解决方案:

$("#sidebar").wrap("<!--googleoff: index--><!--googleon: index>");

第二种解决方案:

来自这个帖子:jQuery comment/uncomment <!--element-->

function comment(element){
    element.wrap(function() {
        alert(this.outerHTML);
        return '<!--googleoff: index-->'+this.outerHTML+'"<!--googleon: index>';
    });
}
comment($('#sidebar'));

第三种解决方案:

$('#sidebar').prepend("<!--googleoff: index-->");
$('#sidebar').append("<!--googleon: index>");

我想要的结果:

<!--googleoff: index--> //start comment tags
 <div id="sidebar"></div>
<!--googleon: index> // tags

【问题讨论】:

    标签: jquery comments


    【解决方案1】:

    试试这个。

    $('#sidebar').before("<!--googleoff: index-->");
    $('#sidebar').after("<!--googleon: index-->");
    

    【讨论】:

    • 它没有用。当我查看源代码时,我找不到评论标签。
    • 如果您使用 chrome,鼠标右键单击然后“检查元素”而不是“查看页面源代码”。 Page Source 表示加载的 Dom 元素,而不是当前的 Dom 元素
    猜你喜欢
    • 2020-10-10
    • 2015-12-19
    • 2018-10-25
    • 1970-01-01
    • 2014-04-02
    • 2011-01-18
    • 2019-05-11
    • 1970-01-01
    • 2017-10-13
    相关资源
    最近更新 更多