This was done before doing web page query
Form get keywords > Processing of SQL statements in the backend > Return data to the frontend to display
Today I suddenly came to how to implement the Ctrl+F function of the browser. Put the data on the page at once, and then use JS to match the content of the page.
No matter what, now the function is completed, and then the optimization is being done
The code copy is 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();
//Save the student number into the output
UserArray.push(userid);
truthname = $(this).children().eq(1).html();
//Save the name in the 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, let me talk about the design ideas below.
Get the data to match and store it in order into the array, and then in the match.
The function indexof that is located in JS substrings returns -1 if it does not match, and the position of the string is returned.
This way the search can be completed. First hide all the data, and then the match will be displayed. That's OK