加载TextBox默认文本,焦点上为空文本框

时间:2013-08-16 19:02:36

标签: javascript asp.net

我有一个文本框: -

<asp:TextBox ID="TextBox3" runat="server" BackColor="Silver" 
            BorderColor="Silver" Height="20px" Style="margin-left: 6px" Width="136px" OnFocus = "onfocus(); return false;"></asp:TextBox>

function onfocus(){ document.getElementById('<%=TextBox3.ClientID%>').value = "";}

上面有默认文字,页面加载: -

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // By Default the date of submission is set to current date. // 
                TextBox3.Text = "Enter Member ID";
            }

当客户点击文本框时,我希望清除默认文本(空文本框),以便客户端可以输入实际ID,而不必手动删除默认文本。

然而,我可视化的方法,并不是使用我编写的代码。

1 个答案:

答案 0 :(得分:5)

如何在输入中使用placeholder

<asp:TextBox ID="TextBox3" placeholder="Member ID" .... ></asp:TextBox>