В моей работе у меня есть лист Excel с тысячами комментариев, которые мне нужно найти и отправить после проверки некоторых документов. Не всегда легко найти правильный комментарий из-за всех номеров форм, разделов, ошибок ... и т. Д. И иногда они очень длинные.
Я начал с этого примера и хотел бы добавить к нему возможность поиска по нескольким словам или буквам (разделенных пробелами) и возможность либо выделить результаты, либо отметить их жирным шрифтом. Все это при сохранении динамического списка, как сейчас. Это означает, что результаты будут отфильтрованы, как я ищу.
СПАСИБО ОГРОМНОЕ! Я ценю вашу помощь:)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url('/css/searchicon.png');
background-position: 10px 12px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myUL {
list-style-type: none;
padding: 0;
margin: 0;
}
#myUL li a {
border: 1px solid #ddd;
margin-top: -1px; /* Prevent double borders */
background-color: #f6f6f6;
padding: 12px;
text-decoration: none;
font-size: 18px;
color: black;
display: block
}
#myUL li a:hover:not(.header) {
background-color: #eee;
}
</style>
</head>
<body>
<h2>My Comments</h2>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for comments.." title="Type in a name">
<ul id="myUL">
<li><a href="#">Form 3001: Section A, name incorrect + Section B, date missing + Section F, title incorrect</a></li>
<li><a href="#">Form 3001: Section A, Street number missing + Section E, date should be before 2019 + Section N, title missing</a></li>
<li><a href="#">Form 3001: Section F, date of birth incorrect + Section H, last name incorrect + Section D, date missing</a></li>
<li><a href="#">Form 3003: Section A, name incorrect + Section B, date missing + Section F, title incorrect</a></li>
<li><a href="#">Form 3003: Section A, Street number missing + Section E, date should be before 2019 + Section N, title missing</a></li>
<li><a href="#">Form 3003: Section F, date of birth incorrect + Section H, last name incorrect + Section D, date missing</a></li>
</ul>
<script>
function myFunction() {
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
ul = document.getElementById("myUL");
li = ul.getElementsByTagName("li");
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
</script>
</body>
</html>