Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
const items = [ { id: 'item1', name: 'Имя 1' }, { id: 'item2', name: 'Имя 2' }, { id: 'item3', name: 'Имя 3' }, { id: 'item4', name: 'Имя 4' } ]; // Все остальное без изменений, кроме createSelect и updateAllSelects function createSelect(index, selectedValue = null) { const select = document.createElement('select'); select.className = 'item-select'; select.name = `bpfile-${index}-filename-0`; // Получаем все выбранные id в других селектах const selectedValues = Array.from(container.querySelectorAll('select.item-select')) .map(s => s.value) .filter(v => v); // Свободные элементы (id), которые не выбраны в других селектах const availableItems = items.filter(item => !selectedValues.includes(item.id)); // Добавляем все опции (id = value, name = текст) items.forEach(item => { const option = document.createElement('option'); option.value = item.id; option.textContent = item.name; select.appendChild(option); }); // Если передано выбранное значение и оно свободно — выбираем его, // иначе выбираем первый свободный элемент или первый элемент массива if (selectedValue && !selectedValues.includes(selectedValue)) { select.value = selectedValue; } else { select.value = availableItems.length > 0 ? availableItems[0].id : items[0].id; } select.addEventListener('change', onSelectChange); return select; } function updateAllSelects() { const selects = Array.from(container.querySelectorAll('select.item-select')); const selectedValues = selects.map(s => s.value); selects.forEach((select, idx) => { const currentValue = select.value; const otherSelected = selectedValues.filter((v, i) => i !== idx); // Доступные элементы — все, кроме выбранных в других, плюс текущий выбранный const availableOptions = items.filter(item => !otherSelected.includes(item.id) || item.id === currentValue ); // Перезаписываем опции select.innerHTML = ''; availableOptions.forEach(item => { const option = document.createElement('option'); option.value = item.id; option.textContent = item.name; select.appendChild(option); }); if (!availableOptions.some(item => item.id === currentValue)) { select.value = availableOptions.length > 0 ? availableOptions[0].id : ''; } else { select.value = currentValue; } }); }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)