The search function of many shopping websites is that you enter something in the text box and press enter to jump to the search page. However, if you press ENTER outside the text box, you will not respond.CodeFor example, the Zhongguancun mall is written in PHP, And the search is a form, which contains a textbox and a submit button. In this way, after pressing the carriage return button in the textbox, it will be automatically submitted to the action in the form, ASP. net write, a page is a form, write a response text box, press enter, and test, IE6, 8, Firefox, chrome browsing normal, code:
<% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Test_mulform.aspx.cs " Inherits = " Test_mulform " %>
<! 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 Runat = "Server" >
< Title > </ Title >
< Script Type = "Text/JavaScript" >
Function Responseenter (e ){
// Return carriage return
VaR Key = Window. Event ? E. keycode: E. Which;
If (Key = 13 ){
// Alert ("Press ENTER ");
Search ();
}
}
Function Search (){
// Search
VaR Key = Document. getelementbyid ( " Key " ). Value;
If (Key. Length = 0 ){
Document. getelementbyid ( " Key " ). Focus (); // Invalid
Alert ( " Enter a search keyword! " );
} Else {
VaR URL = " Searchitem. aspx? Key = " + Encodeuri (key) + " & Amp; typeid = 0 & amp; typename = All Categories " ;
Window. Open (URL );
}
}
</ Script >
</ Head >
< Body >
< Form ID = "Form1" Runat = "Server" Onsubmit = "Return false ;" >
< Input ID = "Key" Type = "Text" Onkeypress = "Responseenter (event );" />
< Button Style = "Cursor: pointer ;" Onclick = "Search ();" Type = "Button" >
Search
</ Button >
< Div > <% = Datetime. Now %> </ Div >
</ Form >
</ Body >
</ Html >