有剃刀文本框默认值消失 [英] have razor text box default value disappear
本文介绍了有剃刀文本框默认值消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有两个文本框的表单.我想要的是当用户单击文本框时,默认值会消失.我正在使用 razor,所以不确定如何添加我认为需要的 onfocus 事件.
I have a form with two text boxes. What I would like is when the user clicks in the text boxes the default values disappears. I am using razor so not sure how to add the onfocus event I think I need.
@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" />
}
推荐答案
您可以使用 placeholder属性.一个例子是这个页面顶部的搜索框
You can user the placeholder attribute. An example of it is the search box at the top of this page
@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 = "person@example.com"})
<input type="submit" class="newsletterGo" value="Go" />
}
此外,您不需要指定 @Value
属性.HTML 帮助程序负责为您设置输入值.
Also, you don't need to specify the @Value
attribute. The HTML helpers take care of setting the input values for you.
这篇关于有剃刀文本框默认值消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文