带有html注释标签的jQuery包装

乔斯

我已经尝试过3种解决方案,但是没有用。

我想在我的侧边栏添加评论标签。

第一个解决方案:

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

第二种解决方案:

从这篇文章:jQuery评论/注释<!-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
易瓦鲁

试试这个。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章