Index.php, html, который имеет " «жесткие» пункты – пункты 1 и 2
Item Selection
- Item 1
- Item 2
Index.php, PHP-код, который добавляет элементы из sql в ul
fetch('get_data.php')
.then(response => response.json())
.then(data => {
const itemList = document.getElementById('itemList');
data.forEach(item => {
const li = document.createElement('li');
li.innerHTML = "";
li.querySelector('span').textContent = item['ItemName'];
itemList.appendChild(li);
});
Index.php, js-код, фильтрующий список
const itemList = document.getElementById('itemList');
const items = itemList.querySelectorAll('li');
const itemSearchInput = document.getElementById('itemSearch');
// Filter item list based on search input
itemSearchInput.addEventListener('input', function() {
const searchQuery = itemSearchInput.value.trim().toLowerCase();
items.forEach(item => {
const itemName = item.querySelector('span').textContent.toLowerCase();
if (itemName.includes(searchQuery)) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
});
Подробнее здесь: https://stackoverflow.com/questions/786 ... -after-php
Мобильная версия