我的 .cshtml 中有以下代码:
@Html.TextArea("txtComments", new { style = "width: 450px;", placeholder = "Enter Comments here" })
但是占位符根本不显示。我错过了什么吗?
来源:
<textarea cols="20" id="txtComments" name="txtComments" placeholder="Enter Comments here" rows="2" style="width: 450px;">
</textarea>
最佳答案
在样式和占位符之前放一个@,就像这样,甚至可以在它之前放上 htmlAttributes:
。
@Html.TextArea("txtComments", htmlAttributes: new { @style = "width: 450px;", @placeholder = "Enter Comments here" })
这是我得到的准确输出:
<textarea cols="20" id="txtComments" name="txtComments" placeholder="Enter Comments here" rows="2" style="width: 450px;"></textarea>
如果显示占位符但仍未显示,请确保您使用的是最新的网络浏览器,您可以在此处找到支持的浏览器列表:http://caniuse.com/input-placeholder
< IE10 does not support it.
如果您确实需要这些浏览器的支持,也许这个解决方案会对您有所帮助:http://webdesignerwall.com/tutorials/cross-browser-html5-placeholder-text
关于c# - MVC Helper TextArea - 占位符不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15021268/