Deploy watermarks and (blur and focus) events for TextBox

Source: Internet
Author: User

At a time, a watermark is decorated for the TextBox. It has two states: blur and focus. Therefore, we canJavascript writes two events:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var watermarkText = "input name ";
Function WaterMarkOnBlur (textbox ){
If (textbox. value. length = 0 ){
Textbox. style. color = "gray ";
Textbox. value = watermarkText;
}
}
Function WaterMartOnfocus (textbox)
{
If (textbox. value = watermarkText ){
Textbox. style. color = "black ";
Textbox. value = "";
}
}
</Script>

Apply the two Javascript events in TextBox:
Copy codeThe Code is as follows:
<Asp: TextBox ID = "TextBox1" runat = "server" Text = "input name"
ForeColor = "Gray" onblur = "WaterMarkOnBlur (this );"
Onfocus = "WaterMartOnfocus (this);">
</Asp: TextBox>

Demo:

Related Article

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.