Guest User

Untitled

a guest
Jan 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <div id="notfound">Ничего не найдено</div>
  2.  
  3. div#notfound{
  4. display:none;
  5. }
  6.  
  7. function myFunction() {
  8. // Declare variables
  9. //добавляем счетчик найденного
  10. found=0;
  11. var input, filter, ul, li, a, i;
  12. input = document.getElementById('myInput');
  13. filter = input.value.toUpperCase();
  14. ul = document.getElementById("myUL");
  15. li = ul.getElementsByTagName('li');
  16. notfound=document.getElementById("notfound");
  17. notfound.style.display="none";//скроем если при предыдущем цикле блок был показан
  18.  
  19. // Loop through all list items, and hide those who don't match the search query
  20. for (i = 0; i < li.length; i++) {
  21. a = li[i].getElementsByTagName("a")[0];
  22. if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
  23. found++;
  24. li[i].style.display = "";
  25. } else {
  26. li[i].style.display = "none";
  27. }
  28.  
  29. }
  30. if(found==0){
  31. //если ничего не найдено покажем блок "Ничего не найдено"
  32. document.getElementById("notfound").style.display="block";
  33. }
  34. }
Add Comment
Please, Sign In to add comment