When the text box gets the focus, if the text box content is the same as the prompt content, the prompt content will naturally disappear.
When the text box does not have any value and the focus is lost, the text box content will generate a new default prompt.
To meet the above requirements, the Code is as follows:
Copy codeThe Code is as follows: <% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Recipe1.aspx. cs" Inherits = "Recipe1" %>
<! 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> Recipe1 </title>
<Script src = "Scripts/jquery-1.4.1-vsdoc.js" type = "text/javascript"> </script>
<Style type = "text/css">
. DefaultText
{
Font-style: italic;
Color: # CCCCCC;
}
</Style>
<Script type = "text/javascript">
$ (Document). ready (function (){
Var searchBox =$ ("# <% = txtSearch. ClientID %>"); // obtain the Server Control ID through ClientID
SearchBox. focus (function (){
If (searchBox. val () = this. title) {// convert the ToolTip attribute of the TextBox Control to Html as the title attribute
SearchBox. val ("");
SearchBox. removeClass ("defaultText ");
}
});
SearchBox. blur (function (){
If (searchBox. val () = ""){
SearchBox. val (this. title );
SearchBox. addClass ("defaultText ");
}
});
SearchBox. blur ();
});
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<P>
</P>
<Div align = "center">
<Fieldset style = "width: 400px; height: 80px;">
<P>
<Asp: TextBox ID = "txtSearch" runat = "server" Width = "200px" CssClass = "defaultText" ToolTip = "Enter the search keyword"> </asp: TextBox>
<Asp: Button ID = "btnSearch" runat = "server" Text = "Search"/> </p>
</Fieldset>
</Div>
</Form>
</Body>
</Html>
Display Effect: