简体   繁体   中英

jquery mobile string search in page text

i am building a JQuery mobile App which contains lots of pages with lots of text in it. Initially when a user opens the app, the title of all pages is visible in a list view with search filter at the top. When a user clicks on the title, a new page gets opened with text on it. i want to build a separate page (like search.html) with only a search input box in it. When a person search for a string like "Some string", the tiles of all the pages which contains that term are visible in a list view and after clicking the title, the detailed page gets opened.

If you're interested in all the text within, say, a <div id="theTarget"> , then*

var theText = document.getElementById("theTarget").textContent;

so you can search it like any other string.

Then, based on the return value of theText.indexOf(searchText) , you can set your corresponding list view entries' CSS styling based on whether you got -1 (no match) or not.

*Note: non-jQuery solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM