JavaScript로 HTML 테이블에있는 모든 td의 배경색을 어떻게 변경할 수 있습니까?
이것은 시도 였지만 작동하지 않습니다.
document.getElementById('AdressenTabelle').td.style.backgroundColor = "#white";
다음은 표의 HTML입니다.
<table border="1" id="AdressenTabelle" class="datatable">
<thead>
<tr>
<th>Firma</th>
<th>Name</th>
<th>Straße</th>
<th>Ort</th>
<th>Rollen</th>
<th>ID</th>
</tr>
</thead>
<tbody class="datatablecontent" onclick="doIt(event)">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
최신 브라우저의 추가 대안
CSS
.myData {
background-color: blue;
}
HTML
<table id="AdressenTabelle">
<thead>
<tr>
<th>One</th>
<th>Two</th>
</tr>
</thead>
<tbody>
<td class="myData">Data one</td>
<td class="myData">Data two</td>
</tbody>
</table>
자바 스크립트
document.styleSheets[1].rules[0].style.backgroundColor = 'white';
에 jsFiddle
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다