Write a hasty, motioned, to be perfected. Copy the following code into a text file and change the file name extension to. html to run.
Copy Code code as follows:
<style type= "Text/css" >
. res
{
color:red;
}
</style>
<script src= "Jquery.min.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
var oldkey = "";
var index =-1;
var pos = new Array ();
var oldcount = 0;
function Search (FLG) {
if (!FLG) {
index++;
index = index = = Oldcount? 0:index;
}
else {
index--;
index = Index < 0 ? OldCount-1: Index;
}
$ (". Result"). Removeclass ("res");
$ ("#toresult"). Remove ();
var key = $ ("#key"). Val ();//Take key value
if (!key) {
Oldkey = "";
return;// Exit
}
If key is empty
if (Oldkey!= key) {
//Reset
index = 0;
$ (". Result"). each (function () {
$ (this). ReplaceWith ($ (this). html ());
});
pos = new Array ();
$ ("body"). HTML ($ ( "Body"). HTML (). Replace (new RegExp (Key, "GM"), "<span id= ' result" + index + "' class= ' result ' >" + key + "</span> ;")); Replace the
$ ("#key"). Val (key);
Oldkey = key;
$ ('. Result '). each (function () {
Pos.push ($ (this). Offset (). top);
});
Oldcount = $ (". Result"). Length;
}
$ (". Result:eq (" + Index + ")"). AddClass ("res");
$ ("Body"). ScrollTop (Pos[index]);
}
</script>
<body>
<div style= "position:fixed; right:20px; top:0; " >
<input id= "Key" type= "text" style= "width:100px;"/>
<input type= "button" value= "Next" onclick= "search ()"/>
<input type= "button" value= "last" onclick= "search (1)"/>
</div>
<div style= "height:50px;" >
</div>
<div style= "height:200px;" >
1 text to search for.
</div>
<div style= "height:200px;" >
2 text to search for.
</div>
<div style= "height:200px;" >
3 Text to search for.
</div>
<div style= "height:200px;" >
4 text to search for.
</div>
<div style= "height:200px;" >
5 text to search for.
</div>
<div style= "height:200px;" >
10 beautiful hometown.
</div>
<div style= "height:200px;" >
11 beautiful hometown.
</div>
<div style= "height:200px;" >
12 beautiful hometown.
</div>
<div style= "height:200px;" >
13 beautiful hometown.
</div>
<div style= "height:200px;" >
14 beautiful hometown.
</div>
<div style= "height:200px;" >
15 beautiful hometown.
</div>
</body>
Here is the main one to provide a train of thought, small partners can not wait to be perfect under their own.