添加HTML5占位符文本到文本框.NET [英] Add HTML5 placeholder text to a textbox .net
本文介绍了添加HTML5占位符文本到文本框.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个标准输入:
<asp:TextBox type="text" runat="server" id="txtSearchTerm" />
我想有这种渲染一个充满活力的 HTML5占位符。是这样的:
'Code Behind
txtSearchTerm.**placeholder** = "Search " + Site.Name
因此,它输出以下HTML:
So that it outputs the following HTML:
<input type="text" runat="server" id="txtSearchTerm"
placeholder="Search Site #1" />
在这里Site.Name =网站#1。
where Site.Name = "Site #1".
txtSearchTerm。占位符是不是一个属性。我有它设置为文本,然后运行JavaScript来显示对焦点/隐藏,而是我宁愿只使用HTML5占位符值。我怎样才能使这个?
txtSearchTerm.placeholder is not a property. I have it set to text and then run javascript to show/hide on focus BUT I would much rather just use the HTML5 placeholder value. How can I render this?
请没有JS /客户端的解决方案。
Please no JS/client side solutions.
推荐答案
您可以使用属性
集合。所以,你会碰到这样的
You could use the Attributes
collection. So you would have something like
txtSearchTerm.Attributes.Add("placeholder", "Search" + Site.Name);
或
txtSearchTerm.Attributes["placeholder"] = "Search" + Site.Name; // or Attributes("placeholder") if you're using vb.net
这篇关于添加HTML5占位符文本到文本框.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文