ASP. NET jQuery instance 1 (create a default prompt in TextBox)

Source: Internet
Author: User

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:

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.