样式中设置content为元素的data-值 p{ color: deepskyblue; } p:before{ content: attr(data-beforeContent); color: darkred; } 然后js修改 $('p').on('click',function(){ $(this).attr('data-beforeContent','我被点击了'); });
样式中设置content为元素的data-值 p{ color: deepskyblue; } p:before{ content: attr(data-beforeContent); color: darkred; } 然后js修改 $('p').on('click',function(){ $(this).attr('data-beforeContent','我被点击了'); });
转载于:https://www.cnblogs.com/guyuedashu/p/11459046.html