The search experience of Baidu and Youku is improved, similar to Google Instant Search

Source: Internet
Author: User

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>

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.