请知悉:本文最近一次更新为 7年 前,文中内容可能已经过时。

事实上这个属性根本没有什么换行的功能,恩,我是指全浏览器兼容的,你光给Chrome或者Firefox搞一个没什么意义。
尤其针对textarea,不如直接用js来的方便,代码如下:

var placeholder = 'This is a line nthis should be a new line';
$('textarea').attr('value', placeholder);
$('textarea').focus(function(){
if($(this).val() === placeholder){
$(this).attr('value', '');
}
});
$('textarea').blur(function(){
if($(this).val() ===''){
$(this).attr('value', placeholder);
}
});

其中n是换行。

代码来着:https://stackoverflow.com/questions/7312623/insert-line-break-inside-placeholder-attribute-of-a-textarea


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《placeholder属性换行》相关的博文:


留言

Admin Avatar
😀
😀😁😂😅😭🤭😋😘🤔😰😱🤪💪👍👎🤝🌹👌