var texts = document.getElementsByClassName("section_text") as HTMLCollectionOf<HTMLElement>;
你可以简单地使用addClass()
:
CSS
.newStyle{
width:100%;
float:left;
}
使用Jquery
$('.section_text input').addClass('newStyle');
使用Javascript
document.querySelector('.section_text input').classList.add('newStyle';
我之前在尝试使用Angular时遇到了类似的问题。问题在于getElementsByClassName
返回的是节点列表,而不是普通数组,因此您无法像尝试的那样访问属性。您可以在这个回答中了解更多信息。