html search box function

墨辰丷
Release: 2018-06-04 14:28:06
Original
4048 people have browsed it

The search function of the html page is mainly used to enter characters in the search box. Let me share with you the search function of the html page through this article. Friends who need it can refer to it.

Recently I am working on a project that has been modified by many people. framework, I feel dizzy when I look at the code every day, but I feel that I have made a lot of progress. I made a backend and configurable frontend to view the different data ranges of the two libraries. I am quite satisfied. I took it out to share it that day. Today I will talk about a function that I have been working on in the past few days, which is the search function of html pages.

This function is mainly used to enter characters in the search box, and then press the previous and next buttons. The matching characters in the query area will be automatically marked with a special style. You can continue to press the previous and next buttons. A button will browse the matching characters in order and use another style to distinguish the current matching character from other matching characters.

The front desk display probably looks like this:

html looks like this:

Copy after login

script code:

Copy after login

Next, remember the implementation principle:

First clear the last query results, and then use regular expressions to match all matches in the area based on the key value. All the characters are added with a special style. For example, a span tag with the class name result is added to the method, and the odKey0 variable is used to record the value of the key (compare first when entering next time. If they are the same, it means that you need to look at the next or previous one. The content of one, there is no need to use regular expression matching when entering), oldCount0 records the total number of queries, and newflag is set to 0 (if it is not the first query, newflag is 1).

Then enter the getNext method. flg indicates whether the user pressed the previous or next button. Use index0 to record which matching character is currently viewed. Compare it with oldCount0 to determine whether it is incrementing or decrementing or setting to 0 ( If it is greater than oldCount0 or less than 0, it will start again).

The focusMove method is an operation that positions the page to the current element.

Jquery methods learned:

eq() Selector: The selector selects elements with a specified index value. For example:$(".contrast .result:eq(1)")selects the second element named result among the elements with class name contrast.

parents() method: all parent elements of the element.$("p").parents('.contrast-wrap'), all elements of the p element whose class name is contrast-wrap.

replace() method: Replace the selected element with the specified html content. Note that the elements of the selected element are also replaced.

offset() method: Returns or sets the offset (position) of the matching element relative to the document.

scrollTop() method: Returns or sets the vertical position of the scroll bar of the matching element.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

Summary of HTML lists, forms, and semantic usage methods

Knowledge points for using postMessage in HTML5 Solve the cross-domain problem of POST in Ajax

##Chart.js lightweight HTML5 chart drawing tool library detailed steps to use

The above is the detailed content of html search box function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!