It was said that it took three hours to see who has implemented the Youtube Instant search abroad last time.
I smiled. After reading the article, I spent three hours implementing the Instant Search Experience of Baidu and Youku.
The difficulty lies in the listening of keyboard input. The built-in keyup function of JQuery and the setTimeout Function of JS are used to achieve better results.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> </title>
<Style type = "text/css">
. Hidden
{
Display: none;
}
. Show
{
Display: block;
Border: 0;
}
# Up
{
Margin:-100px 0 0 0;
Width: 1300px;
Height: 900px;
/* Text-align: center ;*/
}
# GetKey
{
Height: 36px;
Width: pixel PX;
Font-size: large;
}
</Style>
<Script src = "JS/jquery-1.4.2-vsdoc.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
Var baidu = 1; var youku = 0;
Var getKey;
Function gotothere (){
GetKey = $ ("# getKey"). val ();
If (getKey = ""){
// Alert ("sorry ");
// $ ("Up"). className = "show ";
}
Else {
If (baidu = 1 ){
$ ("# Up"). attr ("src", "http://www.baidu.com/s? Wd = "+ encodeURI (getKey) +" & inputT = 624 & ie = UTF-8 ");
}
Else if (youku = 1 ){
$ ("# Up"). attr ("src", "http://www.soku.com/search_video/q_" + getKey );
}
}
}
$ (Function (){
$ ("# GetKey"). keyup (function () {// listen to keyboard press events
Var timer = setTimeout ("gotothere ()", 500); // sometimes the keyboard is pressed too fast and the listening event is too late to respond, so the setTimeout function is used to delay
});
});
$ (Function (){
$ ("# Baidu"). click (function (){
Baidu = 1; youku = 0;
$ ("# Up"). attr ("src", "http://www.baidu.com/s? Wd = "+ encodeURI (getKey) +" & inputT = 624 & ie = UTF-8 ");
});
$ ("# Youku"). click (function (){
Youku = 1; baidu = 0;
$ ("# Up"). attr ("src", "http://www.soku.com/search_video/q_" + getKey );
})
})
</Script>
</Head>
<Body style = "overflow-y: hidden;">
Enter the keyword you want to search: <input id = "getKey" type = "text"/> <a href = "#" id = "baidu"> baidu </a> & nbsp | & nbsp <a href = "#" id = "youku"> youku </a> <br/>
<Div style = "overflow: hidden"> <iframe id = "up" class = "show" frameborder = "0"> </iframe> </div>
</Body>
</Html>