使于输入密码的textBox中显示默认提示
想在用于输入密码的textBox中显示默认提示“请输入密码”,获得焦点后,提示隐藏,
C# code
protected void Page_Load(object sender, EventArgs e)
{
TextBoxLoginName.Attributes.Add("onfocus","if(this.value=='请输入登录名'){this.value=''}" );
TextBoxLoginName.Attributes.Add("onblur", "if(this.value==''){this.value='请输入登录名'}");
TextBoxPassword.Attributes.Add("value", "请输入密码");
TextBoxPassword.Attributes.Add("onfocus", "if(this.value=='请输入密码'){this.value=''}");
TextBoxPassword.Attributes.Add("onblur", "if(this.value==''){this.value='请输入密码'}");
}
但是TextBox的TextMode属性被设置为Password,所以默认提示会显示为“.......”,请问该怎么解决呢?
------解决方案--------------------
------解决方案--------------------HTML 5中有placehold这个属性,或者有jquery的插件
http://phoetry.me/archives/jquery-placeholder.html
当然还可以自己来实现
------解决方案--------------------https://github.com/danielstocks/jQuery-Placeholder
------解决方案--------------------
你的代码这样改即可
protected void Page_Load(object sender, EventArgs e)
{
TextBoxLoginName.Attributes.Add("onfocus","if(this.value=='请输入登录名'){this.type='password';this.value=''}" );
TextBoxLoginName.Attributes.Add("onblur", "if(this.value==''){this.type='text';this.value='请输入登录名'}");
TextBoxPassword.Attributes.Add("value", "请输入密码");
TextBoxPassword.Attributes.Add("onfocus", "if(this.value=='请输入密码'){this.type='password';this.value=''}");
TextBoxPassword.Attributes.Add("onblur", "if(this.value==''){this.type='text';this.value='请输入密码'}");
}