使用jQuery选择和 *** 作CSS伪元素,例如:: before和:: after

使用jQuery选择和 *** 作CSS伪元素,例如:: before和:: after,第1张

使用jQuery选择和 *** 作CSS伪元素,例如:: before和:: after

您还可以将内容传递给具有data属性的伪元素,然后使用jQuery进行 *** 作:

在HTML中:

<span>foo</span>

在jQuery中:

$('span').hover(function(){    $(this).attr('data-content','bar');});

在CSS中:

span:after {    content: attr(data-content) ' any other text you may want';}

如果要防止显示“其他文本”,可以将其与seucolega的解决方案结合使用,如下所示:

在HTML中:

<span>foo</span>

在jQuery中:

$('span').hover(function(){    $(this).addClass('change').attr('data-content','bar');});

在CSS中:

span.change:after {    content: attr(data-content) ' any other text you may want';}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4925074.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存