Показать сообщение отдельно
  #16 (permalink)  
Старый 14.09.2016, 18:10
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,124

Сообщение от mikhael
это не первый input, он может быть и 5 и 10.
какая разница ....

<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>

  <script>
 window.addEventListener("DOMContentLoaded", function() {
    [{id : 4, r : 40},{id : 8, r : 25}].forEach(function(c) {
        var b = document.querySelector("[id=edit-submitted-"+c.id+"otvet]"),
            a = document.querySelector("[id=edit-submitted-"+c.id+"rez]");
        b.addEventListener("input", function() {
           a.value = +(this.value == c.r)
        })
    })
});
  </script>
</head>

<body>

<form>
<div class="form-item webform-component webform-component-number webform-component--4otvet webform-container-inline form-group form-inline form-item form-item-submitted-4otvet form-type-webform-number form-group"> <label class="control-label" for="edit-submitted-4otvet">Ответ</label>
<input class="form-control form-text form-number" type="text" id="edit-submitted-4otvet" name="submitted[4otvet]" step="1"></div>
<div class="form-item webform-component webform-component-number webform-component--4rez webform-container-inline form-group form-inline form-item form-item-submitted-4rez form-type-webform-number form-group"> <label class="control-label" for="edit-submitted-4rez">4rez</label>
<input class="form-control form-text form-number" type="text" id="edit-submitted-4rez" name="submitted[4rez]" value="0" step="1"></div>
..........
<div class="form-item webform-component webform-component-number webform-component--8otvet webform-container-inline form-group form-inline form-item form-item-submitted-8otvet form-type-webform-number form-group"> <label class="control-label" for="edit-submitted-8otvet">Ответ</label>
<input class="form-control form-text form-number" type="text" id="edit-submitted-8otvet" name="submitted[8otvet]" step="1"></div>
<div class="form-item webform-component webform-component-number webform-component--8rez webform-container-inline form-group form-inline form-item form-item-submitted-8rez form-type-webform-number form-group"> <label class="control-label" for="edit-submitted-8rez">8rez</label>
<input class="form-control form-text form-number" type="text" id="edit-submitted-8rez" name="submitted[8rez]" value="0" step="1"></div>
</form>



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