В общем, достаточно стандартная задача. Найти все элементы input, имеющие определённый класс и что-то с ними сделать. Почему-то свойство className для всех чекбоксов оказывается пустой строкой. Код:
| Код | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript"> window.onload = function() { var ut_vse = document.getElementById("ut_vse"); ut_vse.onclick = function() { var inputs = document.getElementsByTagName("input"); for (var i = 0; i < inputs.length; i++) { alert(inputs[0].className); } } }
</script> </head> <body> Hello, annotation world! <br>
<table border="1"> <tr><td>Утопить<br><span>утопить все</span><input id="ut_vse" type="checkbox"/></td> <td>Наименование</td> <td>Спустить на воду<br><span>спустить на воду все</span><input id="spustit_vse" type="checkbox"/></td></tr> <tr> <td><input class="ut" type="checkbox"/></td>
<td><p>Sokol 0</td> <td><input class="spustit" type="checkbox"/></td> </tr> <tr> <td><input class="ut" type="checkbox"/></td> <td><p>Sokol 1</td> <td><input class="spustit" type="checkbox"/></td> </tr>
<tr> <td><input class="ut" type="checkbox"/></td> <td><p>Sokol 2</td> <td><input class="spustit" type="checkbox"/></td> </tr> <tr> <td><input class="ut" type="checkbox"/></td> <td><p>Sokol 3</td>
<td><input class="spustit" type="checkbox"/></td> </tr> <tr> <td><input class="ut" type="checkbox"/></td> <td><p>Sokol 4</td> <td><input class="spustit" type="checkbox"/></td> </tr> <tr>
<td><input class="ut" type="checkbox"/></td> <td><p>Sokol 5</td> <td><input class="spustit" type="checkbox"/></td> </tr> <tr> <td><input class="ut" type="checkbox"/></td> <td><p>Sokol 6</td> <td><input class="spustit" type="checkbox"/></td>
</tr> <tr> <td><input class="ut" type="checkbox"/></td> <td><p>Sokol 7</td> <td><input class="spustit" type="checkbox"/></td> </tr> <tr> <td><input class="ut" type="checkbox"/></td>
<td><p>Sokol 8</td> <td><input class="spustit" type="checkbox"/></td> </tr> <tr> <td><input class="ut" type="checkbox"/></td> <td><p>Sokol 9</td> <td><input class="spustit" type="checkbox"/></td> </tr> </table> </body> </html>
|
Все алерты выводят пустое окошко. Если заменить className на getAttribute('class'), то возвращается null. А классы, как видно из кода, у чекбоксов есть.
|