Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="jumbotron">
- <h1>Работа с радиокнопками</h1>
- <div class="btn-group btn-group-toggle" data-toggle="buttons">
- <label class="btn btn-secondary active bg-danger">
- <input type="radio" name="options" id="option1" autocomplete="off" value="red"> Красный
- </label>
- <label class="btn btn-secondary bg-primary">
- <input type="radio" name="options" id="option2" autocomplete="off" value="blue"> Синий
- </label>
- <label class="btn btn-secondary bg-success">
- <input type="radio" name="options" id="option3" autocomplete="off" value="green"> Зеленый
- </label>
- </div>
- <button type="button" class="btn btn-primary btn-sm btn-block" id="checks">Применить</button>
- </div>
- var radio = document.getElementsByName('options');
- for ( var i=0; i<radio.length; i++ ){
- radio[i].onchange = f2;
- }
- function f2() {
- console.log(this.value);
- //Получаем this.value
- }
- document.getElementById('checks').onclick = checkRadio;
- function checkRadio() {
- var b = document.getElementsByName('options');
- for ( var i=0; i<b.length; i++){
- if ( b[i].checked ){
- document.body.style.backgroundColor = 'red';
- }
- }
- }
Add Comment
Please, Sign In to add comment