Home > Article > Web Front-end > How does jquery find the string of the current page and locate that string position? _html/css_WEB-ITnose
How does jquery find the string of the current page and locate that string position? If it cannot be found, it will prompt not found. It's a bit similar to the Ctrl f function of a browser. Please give me a solution. Thank you all. I wrote one before, but it is not compatible with Google Chrome
Directly indexOf the document
Directly indexOf the document
Directly indexOf the document
();
var searchText = $("#keyword").val();
var regExp = new RegExp(searchText, 'g'); //Create a regular expression, g represents global, if If g is not used, the search will not continue after finding the first one; 🎜> var newHtml = html.replace(regExp, '' searchText ''); //Replace the found keywords and add the highlight attribute;
var ele = $(".highlight"). eq(0);
var top = ele.offset().top;
$('html,body').animate({ scrollTop: top }, 300); > })
function clearSelection() {
$('p').each(function () {
//Find all elements with highlight attribute;
$(this).find ('.highlight').each(function () {
} );