如何在打字稿中设置背景颜色?

时间:2017-03-01 08:38:04

标签: css typescript background-color

如何使用下面代码的打字稿中的classname设置背景颜色??

abc.innerHTML = abc.innerHTML.replace(element,'<span class="classname">text</span>');

1 个答案:

答案 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';
}