C# textbox 先显示文字 单击后文字消失 急!!!

如题所述

如果是这样,点击文本框文字就消失了.
private void textBox1_Click(object sender, EventArgs e)
{
this.textBox1.Text = "";//或者 this.textBox1.Text = string.Empty;
//如果在系统中设置了获取焦点,清空this.textBox1.Text ,那么,请检查
}
//如果这样,也会造成文字消失.
private void textBox1_Enter(object sender, EventArgs e)
{
this.textBox1.Text = string.Empty;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-06-04
点击文本框清空可用js 脚本实现!

<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="TextBox1" Text="请输入用户名" runat="server"></asp:TextBox>
</div>
<script type="text/javascript">
document.getElementById("TextBox1").onclick=function()
{
if(document.getElementById("TextBox1").value=="请输入用户名")
{
document.getElementById("TextBox1").value="";
}
}
</script>
</form>
</body>
第2个回答  2012-06-06
textBox1.Text="你要输入的文字!";
private void textBox1_Click(object sender, EventArgs e)
{
this.textBox1.Text = "";
}
第3个回答  2012-06-04
textbox1.Attributes.Add(“onclick”,"this.value=''");
第4个回答  2012-06-04
找到textbox里的focuse on 还是fouse里写代码:// 这里有点忘记了
textbox.Text="";
相似回答