第一种方法: 利用 标签的data-* 属性和content:attr(data-*) 结合
CSS
.refresh-item-list { margin: 0 1rem 1rem; box-shadow: 0 0 4px 0 rgba(38, 49, 190, 0.2); border-radius: 8px; &:before { content: attr(data-content-before); position: absolute; top: -30px; } }
HTML
<div className="refresh-item-list" data-content-before="下拉刷新"> xxx </div>
JS
const list = document.querySelector('.refresh-item-list'); list.attributes[1].value ='要修改的值';
第二种方法: