< script > addAll();
var input = document.getElementById('name');
var ul = document.getElementsByClassName('countries')[0];
var li = ul.children;
var bt = document.getElementById('hide_show');
input.onkeyup = function (event) {
event = event || window.event;
if (input.value.length == 0) {
addAll();
} else {
var result = search(input.value);
if ((result === undefined) || (result.length < 1)) {
notFound();
} else {
removeChildren(ul);
for (var i = 0; i < result.length; i++) {
var item = document.createElement('li');
item.innerHTML = result[i].innerHTML;
//подсветить в результате то, что совпадает с введенным значением НУЖНО ТОЛЬКО ПЕРВЫЕ БУКВЫ!!!
ul.appendChild(item);
};
}
}
};
function search(text) {
var mas_li = [];
//поиск нужно возобновлять снова по всему списку (список хранится в 'li')
for (var i = 0; i < li.length; i++) {
if (li[i].innerHTML.indexOf(text) != -1) {
mas_li.push(li[i]);
};
};
return mas_li
}
function notFound() {
removeChildren(ul);
var item = document.createElement('li');
item.innerHTML = 'Ничего не найдено'
ul.appendChild(item);
}
function removeChildren(elem) {
try {
elem.innerHTML = '';
} catch (e) {
while (elem.firstChild) {
elem.removeChild(elem.firstChild);
}
}
}
function addAll() {
$.ajax({
url: 'countries.html', // корне тупо лежит страница списком стран
success: function (data) {
$('.countries').html(data);
}
});
}
bt.onclick = function () {
if (ul.style.display != 'none') {
ul.style.display = 'none';
} else {
ul.style.display = 'list-item';
}
}; < /html>
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.