如何使用下面代码的打字稿中的classname设置背景颜色??
abc.innerHTML = abc.innerHTML.replace(element,'<span class="classname">text</span>');
答案 0 :(得分:2)
你可以像在JS中那样做,但是转换为<HTMLElement>
is required:
var def = "Maximus";
var li = document.querySelectorAll("#id li");
for (var i = 0; i < li.length; i++) {
var element = li[i];
element.innerHTML = element.innerHTML.replace(def, '<span class="classname">text</span>');
let spanEl = <HTMLElement>element.querySelector('span.classname');
spanEl.style.color = 'orange';
}