Показать сообщение отдельно
  #5 (permalink)  
Старый 26.07.2016, 00:51
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,071

Valper,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
 </head>

<body>
<ul class="questions__list">
 <li class="questions__item">
 <span>1.</span>I __________ a teacher.
 <div class="anwers">
 <div class="option-group"></br>
 <input type="radio" value="1" name="1" id="1-1" required="" />
 <label for="1-1">am</label>
 <input type="radio" value="2" name="1" id="1-2" required="" />
 <label for="1-2">are</label>
 <input type="radio" value="3" name="1" id="1-3" required="" />
 <label for="1-3">be</label>
 <input type="radio" value="4" name="1" id="1-4" required="" />
 <label for="1-4">is</label>
 <div class="option-group option-group--dont-know">
 <input type="radio" value="0" name="1" id="1-0" required="" />
 <label for="1-0">я не знаю ответ</label>
 </div>
 </div>
 </div>
 </li>
 </ul>
<script>
  window.addEventListener('DOMContentLoaded', function() {
      [].forEach.call(document.querySelectorAll('.questions__item'), function(li) {
          var span = li.querySelector('span'),
              text = span.nextSibling.textContent,
              dont = li.querySelector('.option-group--dont-know label');
          [].forEach.call(li.querySelectorAll('[type="radio"]'), function(input) {
              input.addEventListener('change', function() {
                  var label = li.querySelector('[for="' + this.id + '"]');
                  span.nextSibling.textContent = label == dont ? text : text.replace(/_+/, label.textContent)
              });
          });

      });
  });
</script>
</body>
</html>
Ответить с цитированием