On the realization of page content search based on web front page _javascript skills

Source: Internet
Author: User

This is what you do before you make a query on a Web page.

Form get keyword –> incoming back-end SQL statement processing –> data back to front display

Today suddenly to the ctrl+f of the browser how to achieve this function, the data once on the page, and then use JS to match the content of the page.

Anyway, now that you've done the function, and then you're doing the optimization

Copy Code code as follows:

$ (function () {
var userarray = new Array ();
var turenamearray = new Array ();
var table = $ ("Table>tbody");

Table.children (). each (function () {
UserID = $ (this). Children (). EQ (0). html ();
To deposit the number in the output
Userarray.push (userid);
Turename = $ (this). Children (). EQ (1). html ();
Save the name in an array
Turenamearray.push (Turename);
});
//
$ ("#search"). focus (function () {
$ (this). Val ("");
}). blur (function () {
val = $.trim ($ (this). Val ());
if (val = = "")
{
$ (this). Val ("Work Number/name");
}
});
$ (". Btn"). Click (function () {
val = $ ("#search"). Val ();
if (val = = "Work number/name")
{
Alert ("Please enter a valid work number and name");
}
Else
{
Table.children (). Hide ("100");
if (!isnan (val))
{
HANLD (Userarray,val);
}
Else
{
HANLD (Turenamearray,val);
}
}
});
function hanld (array,value)
{
for (i=0;i<array.length;i++)
{
if (Array[i].indexof (value)!==-1)
{
Table.children (). EQ (i)-Show ("1000");
}
}
}

The code is above, I'll say the design idea below.

Get the data that you want to match into the array in order, and then match it.

The function that locates with the substring of JS IndexOf if does not match returns 1, the match returns the position of the string.

This will allow you to complete the search. The first is to hide all the data and then the matching success is displayed. That's OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.