我有一个标准的输入:
<asp:TextBox type="text" runat="server" id="txtSearchTerm" />
我想使用一个动态的HTML5占位符进行渲染。就像是:
'Code Behind txtSearchTerm.**placeholder** = "Search " + Site.Name
所以它输出以下HTML:
<input type="text" runat="server" id="txtSearchTerm" placeholder="Search Site #1" />
其中Site.Name =“Site#1”。
txtSearchTerm.placeholder不是属性。我把它设置为文本,然后运行javascript来显示/隐藏焦点,但我更宁愿只使用HTML5占位符值。如何呈现?
请不要JS /客户端解决方案。
解决方法
您可以使用Attributes集合。所以你会有类似的东西
txtSearchTerm.Attributes.Add("placeholder","Search" + Site.Name);
要么
txtSearchTerm.Attributes["placeholder"] = "Search" + Site.Name; // or Attributes("placeholder") if you're using vb.net
如果您使用资源进行本地化/翻译:
txtSearchTerm.Attributes["placeholder"] = GetLocalResourceObject("YourLocalResourceName").ToString();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。