我尝试了一些方法,但没有一个奏效。有人知道绕过这个的妙招吗?
<textarea placeholder='This is a line \n this should be a new line'></textarea>
<textarea placeholder='This is a line
should this be a new line?'></textarea> <!-- this works in chrome apparently -->
更新:它不工作在chrome。它只是textarea的宽度。
参见:http://jsfiddle.net/pdXRx/
但需要注意的是,问题的前提与W3规范不一致,因此不能保证行为,解决方案使用&x10;工作时<textarea>是要在HTML中定义:
<textarea
placeholder="HTML entity works but unicode entity hard-coded \u000A !">
</textarea>
但是如果<textarea>是用JavaScript创建的,那么 实体将在输出中硬编码。然而,使用unicode等效的\u000A是可以的:
let myArea = document.createElement("textarea");
myArea.placeholder = "Unicode works \u000A But HTML entity hard-coded !";
如果你在ASP中使用Razor。NET项目,你可以做下面的事情,这对很长的占位符值很有帮助:
@{
string strPlaceholder = "Shipment Id to Update, Container Id to Update, New Tracking Number \r\n"
+ "Shipment Id to Update, Container Id to Update, New Tracking Number \r\n"
+ "Shipment Id to Update, Container Id to Update, New Tracking Number \r\n"
+ "\r\n"
+ "i.e. to update all containers with shipment Id 5803407, etner like this: \r\n"
+ "5803407, , 1Z20579A0322337062 \r\n"
+ "\r\n"
+ "or to update a specific container Id, enter like this: \r\n"
+ "5803407, 112546247, 1Z20579A0322337062 \r\n"
;
}
<textarea type="text" class="form-control" style="height:650px;" id="ShipmentList" name="ShipmentList"
placeholder="@strPlaceholder" required></textarea>