3

Есть таблица:

<table class="table_dark">
    <caption>FLIGHTS</caption>
    <tr>
        <th>Id</th>
        <th>Navigation</th>
        <th>Registration to flight</th>
    </tr>
    <c:forEach var="flight" items="${flights}">
        <tr id="tr${flight.id}">
            <td>${flight.id}</td>
            <td>${flight.navigation}</td>
            <td><input type="submit" onclick="registrationClickHandler(event);" value="Register" id="register${flight.id}" class="myButtonStyle1"></td>
        </tr>
    </c:forEach>
</table>

Рисунок таблицы:

введите сюда описание изображения

Необходимо при нажатии на кнопку Register скрывать все остальные tr. А при нажатии на кнопку Close(id=closeButton) снова отображать.

Вопрос: как лучше это сделать?

1
  • 1
    Через jQuery и методы hide и show.
    – Alex78191
    28 мая 2017 в 18:53

1 ответ 1

3

Как советуют в комментариях, задачу можно решить с помощью jquery и методов hide и show:

$('input').click(function() {
  $('.row-that-can-be-hidden').hide();
  $(this).closest('.row-that-can-be-hidden').show();
});

$('button').click(function() {
  $('.row-that-can-be-hidden').show();
});
table, th, td {
  border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<button>close</button>
<table class="table_dark">
  <caption>FLIGHTS</caption>
  <tr>
    <th>Id</th>
    <th>Navigation</th>
    <th>Registration to flight</th>
  </tr>
  <tr id="tr1" class="row-that-can-be-hidden">
    <td>1</td>
    <td>Минск Париж</td>
    <td><input type="submit" value="Register" id="register1" class="myButtonStyle1"></td>
  </tr>
  <tr id="tr2" class="row-that-can-be-hidden">
    <td>2</td>
    <td>Минск Краков</td>
    <td><input type="submit" value="Register" id="register2" class="myButtonStyle1"></td>
  </tr>
</table>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.