<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<img class="image-placeholder" />
<img class="image-placeholder" />
<img class="image-placeholder" />
<label><input type="radio" name="img" value="0" checked>ЧБ</label>
<label><input type="radio" name="img" value="1">Цвет</label>
</body>
<script>
const images = {
"0": [
'https://image.flaticon.com/icons/svg/246/246144.svg',
'https://image.flaticon.com/icons/svg/1383/1383327.svg',
'https://image.flaticon.com/icons/svg/324/324084.svg',
],
"1": [
'https://image.flaticon.com/icons/svg/220/220603.svg',
'https://image.flaticon.com/icons/png/512/1383/1383260.png',
'https://image.flaticon.com/icons/png/512/324/324107.png',
]
};
document.addEventListener('DOMContentLoaded', () => {
const inputRadios = document.querySelectorAll('input[name="img"]');
const imagePlaceholders = document.querySelectorAll('img.image-placeholder');
function onChange() {
const { value } = [...inputRadios].find(i => i.checked === true);
imagePlaceholders.forEach((imgTag, index) => imgTag.src = images[value][index]);
}
inputRadios.forEach(r => r.addEventListener('change', onChange));
onChange();
});
</script>
</html>