1

我设法在 C# 中动态创建文本框。当atextbox有文字时,我可以让它在我点击它时消失吗?

我需要在文本框中输入一个词,这是 Oracle 中选择的结果。

4

2 回答 2

4

为 TextBox 的 Text 属性赋值。然后您可以订阅 GotFocus 事件,并将文本值设置为空字符串。

// Holds a value determining if this is the first time the box has been clicked
// So that the text value is not always wiped out.
bool hasBeenClicked = false;

private void TextBox_Focus(object sender, RoutedEventArgs e)
{
    if (!hasBeenClicked)
    {
        TextBox box = sender as TextBox;
        box.Text = String.Empty;
        hasBeenClicked = true;
    }
}
于 2013-02-28T10:55:39.327 回答
1

javascript 适用于删除。

onclick="$(this).val('');"

或者,您可以使用 HTML5占位符

于 2013-02-28T11:04:25.733 回答