Guest User

Untitled

a guest
Jun 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <div class="jumbotron">
  2. <h1>Работа с радиокнопками</h1>
  3. <div class="btn-group btn-group-toggle" data-toggle="buttons">
  4. <label class="btn btn-secondary active bg-danger">
  5. <input type="radio" name="options" id="option1" autocomplete="off" value="red"> Красный
  6. </label>
  7. <label class="btn btn-secondary bg-primary">
  8. <input type="radio" name="options" id="option2" autocomplete="off" value="blue"> Синий
  9. </label>
  10. <label class="btn btn-secondary bg-success">
  11. <input type="radio" name="options" id="option3" autocomplete="off" value="green"> Зеленый
  12. </label>
  13. </div>
  14. <button type="button" class="btn btn-primary btn-sm btn-block" id="checks">Применить</button>
  15. </div>
  16.  
  17. var radio = document.getElementsByName('options');
  18. for ( var i=0; i<radio.length; i++ ){
  19. radio[i].onchange = f2;
  20. }
  21. function f2() {
  22. console.log(this.value);
  23. //Получаем this.value
  24.  
  25. }
  26. document.getElementById('checks').onclick = checkRadio;
  27.  
  28. function checkRadio() {
  29. var b = document.getElementsByName('options');
  30. for ( var i=0; i<b.length; i++){
  31. if ( b[i].checked ){
  32. document.body.style.backgroundColor = 'red';
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment