如何在ASP.Net MVC的文本框中显示水印而不是值? [英] How to display watermark instead of value in textbox in ASP.Net MVC?

查看:107
本文介绍了如何在ASP.Net MVC的文本框中显示水印而不是值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为

<%= Html.TextBoxFor(m => m.Patient.Weight, new { title = "Weight" , style = "width: 3em", @class = "fieldRequired watermark" }) %> pounds</div>

当我运行应用程序时,在文本框中输入了.当我从文本框中删除值时,它将显示水印.因此,如何制作?

when I run the application I got in my text box. When I delete the value from the textbox it will show watermark. So,How do I make like ?

推荐答案

您要查找的术语是占位符.

The term you're looking for is placeholder.

HTML 5提供了一个用于指定占位符的选项.

There's an option with HTML 5 to specify a placeholder.

<input name="name" type="text" placeholder="Your name...">
@Html.TextBoxFor(m => m.Name, new { placeholder="Your Name..." })

但是,并非所有浏览器都支持它.因此,您可以使用JavaScript.

However, it's not supported on all browsers. So you're off to JavaScript land.

在NuGet上,这是一个受欢迎的选项-jQuery.placeholder. HTML 5属性,并为不支持HTML 5的浏览器处理后退.

Here's a popular option on NuGet - jQuery.placeholder. It'll read the HTML 5 attributes and handle fall-back for browsers that don't support it.

只需在脚本onload处添加脚本即可.还有一些CSS类,检查其文档以获取更多信息.

Just add the script at this in the document onload. And some css classes, check their docs for further info.

$('input, textarea').placeholder();

编辑:所有主要的现代浏览器都支持占位符

这篇关于如何在ASP.Net MVC的文本框中显示水印而不是值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆