2011-12-08 32 views
1

我有一個窗體有兩個文本框。我想要的是,當用戶點擊文本框時,默認值消失。我正在使用剃鬚刀,所以不知道如何添加我認爲需要的onfocus事件。有剃鬚刀文本框默認值消失

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "newsletterform" })) 
{ 
    @Html.TextBoxFor(m => m.Name, new { @Value = "Name"}) 

    @Html.TextBoxFor(m => m.Email, new { @Value = "Email"}) 

    <input type="submit" class="newsletterGo" value="Go" /> 
} 

回答

8

您可以使用placeholder屬性。它的一個例子是在本頁面

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @class = "newsletterform" })) 
{ 
    @Html.TextBoxFor(m => m.Name, new { placeholder = "Default Name"}) 

    @Html.TextBoxFor(m => m.Email, new { placeholder = "[email protected]"}) 

    <input type="submit" class="newsletterGo" value="Go" /> 
} 

而且,你不需要指定@Value屬性頂部的搜索框。 HTML助手負責爲您設置輸入值。

+0

非常感謝 – Beginner