aspx
<
div
>
< asp:TextBox ID = " txtUser " runat = " server " Text = " 请输入用户名 " ></ asp:TextBox >
< br />
< asp:TextBox ID = " txtPwd " runat = " server " TextMode = " Password " ></ asp:TextBox >
</ div >
< asp:TextBox ID = " txtUser " runat = " server " Text = " 请输入用户名 " ></ asp:TextBox >
< br />
< asp:TextBox ID = " txtPwd " runat = " server " TextMode = " Password " ></ asp:TextBox >
</ div >
.aspx.cs
protected
void
Page_Load(
object
sender, EventArgs e)
{
txtUser.Attributes.Add("OnFocus", "if(this.value=='请输入用户名') {this.value=''}");
txtUser.Attributes.Add("OnBlur", "if(this.value==''){this.value='请输入用户名'}");
txtPwd.Attributes.Add("Value", "请输入密码");
txtPwd.Attributes.Add("OnFocus", "if(this.value=='请输入密码'){this.value=''}");
}
{
txtUser.Attributes.Add("OnFocus", "if(this.value=='请输入用户名') {this.value=''}");
txtUser.Attributes.Add("OnBlur", "if(this.value==''){this.value='请输入用户名'}");
txtPwd.Attributes.Add("Value", "请输入密码");
txtPwd.Attributes.Add("OnFocus", "if(this.value=='请输入密码'){this.value=''}");
}