
JavaScript
- 19 ответов
- 0 вопросов
13
Вклад в тег
<div class="advantages_item">
<img src="img/Услуги.jpg" alt="" />
<h2>У нас вы можете:</h2>
<p>Lorem ipsum dolor sit amet.</p>
</div>
<div class="advantages_item">
<img src="img/Услуги.jpg" alt="" />
<h2>У нас вы можете:</h2>
<p>Lorem ipsum dolor sit amet.</p>
</div>
<div class="advantages_item">
<img src="img/Услуги.jpg" alt="" />
<h2>У нас вы можете:</h2>
<p>Lorem ipsum dolor sit amet.</p>
</div>
import PropTypes from 'prop-types';
class Component extends React.Component {
render() {
return (
<h2>{this.props.title}</h2>
);
}
}
Component.propTypes = {
title: PropTypes.string
};
querySelectorAll
возвращает NodeList всеx найденный нод по селктору. В вашем случае в документе есть 2 ноды попадающие под искомый селектор - input
.[0]
и записываете метод onclick
для 1-ого элемента. Тем самым игнорируя 2-ой элемент(2-ой инпут).onclick
.const inputList = document.querySelectorAll("input");
inputList.forEach(input => {
input.onclick = function() {
if ((input.checked == true) && (input.value == "1")) {
document.body.style.backgroundColor = "#00ff00";
} else if ((input.checked == true) && (input.value == "2")) {
document.body.style.backgroundColor = "#ccff00";
} else {
document.body.style.backgroundColor = "#03f3f3";
}
};
})