You could also pass the content to the pseudo element with a data attribute and then use jQuery to manipulate that:
(您还可以将内容传递给具有data属性的伪元素,然后使用jQuery进行操作:)
In HTML:
(在HTML中:)
<span>foo</span>
In jQuery:
(在jQuery中:)
$('span').hover(function(){
$(this).attr('data-content','bar');
});
In CSS:
(在CSS中:)
span:after {
content: attr(data-content) ' any other text you may want';
}
If you want to prevent the 'other text' from showing up, you could combine this with seucolega's solution like this:
(如果要防止显示“其他文本”,可以将其与seucolega的解决方案结合使用,如下所示:)
In HTML:
(在HTML中:)
<span>foo</span>
In jQuery:
(在jQuery中:)
$('span').hover(function(){
$(this).addClass('change').attr('data-content','bar');
});
In CSS:
(在CSS中:)
span.change:after {
content: attr(data-content) ' any other text you may want';
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…