Good day. I looked on the Internet, examples of many different search words on the page, but usually this is the search function for the user. And I need the function to work imperceptibly for the user, and when detecting or the absence of the required text, produce certain actions.
Closed due to the fact that the essence of the question is not clear to the participants Visman , user194374, Vadim Ovchinnikov , fori1ton , aleksandr barakin January 21, '17 at 13:46 .
Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
- 2What does the search function mean for the user ? - Grundy
- can you give an example please? - spectre_it
|
1 answer
I prefer to use RexExp in such situations:
(function() { var text = 'обычно это именно функция', // Текст, который надо найти regexp = new RegExp(text, 'i'); if (regexp.exec(document.getElementById('text').innerHTML)) { // Если нашло, то выполнить это var reg = new RegExp(text, 'g'); document.getElementById('text').innerHTML = document.getElementById('text').innerHTML.replace(reg, '<span style="color: red">' + text + '</span>'); } else { // Если не нашло, то выполнить это console.log('Текст не найдет'); }; }()); <p id="text">Добрый день. Искал в интернете, примеров много разных поиска слова по странице, но обычно это именно функция поиска для юзера. А мне нужно, чтобы функция работала незаметно для пользователя и при обнаружении или отсутствии искомого текста производила определенные действия.</p> |