【发布时间】:2020-01-31 02:24:41
【问题描述】:
const tour = document.querySelector('.tour__heading');
const addSection = e => {
e.target.innerHTML.replace('SHOW','red');
};
tour.addEventListener('click', addSection);
我可以使用 e.target 来改变上面的 HTML 文本吗?
【问题讨论】:
-
replace不会就地更改字符串(字符串在 JS 中是不可变的)。您需要将innerHTML设置为等于.replace()的返回值
标签: javascript html innerhtml