在 <textarea> 中可以有多行 HTML5 占位符文本吗? [英] Can you have multiline HTML5 placeholder text in a <textarea>?

查看:31
本文介绍了在 <textarea> 中可以有多行 HTML5 占位符文本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用 HTML5 的占位符属性将注意力集中在文本字段中时,我的文本字段中的幽灵文本会消失:

I have ghost text in textfields that disappear when you focus on them using HTML5's placeholder attribute:

<input type="text" name="email" placeholder="Enter email"/>

我想使用相同的机制在 textarea 中包含多行占位符文本,可能是这样的:

I want to use that same mechanism to have multiline placeholder text in a textarea, maybe something like this:

<textarea name="story" placeholder="Enter story
 next line
 more"></textarea>

但是那些 出现在文本中并且不会导致换行......有没有办法拥有多行占位符?

But those s show up in the text and don't cause newlines... Is there a way to have a multiline placeholder?

更新:我让它起作用的唯一方法是利用 jQuery Watermark 插件,它接受占位符文本中的 HTML:

UPDATE: The only way I got this to work was utilizing the jQuery Watermark plugin, which accepts HTML in the placeholder text:

$('.textarea_class').watermark('Enter story<br/> * newline', {fallback: false});

推荐答案

For