您的位置:首页 > Web前端 > HTML5

HTML5的placeholder属性如何实现换行

2015-02-25 17:28 302 查看
在HTML5中,placeholder是一个非常有用的属性,当控件中无内容时可以代替UI控件的提示功能,而不需要写额外的代码。但如果有一个textarea控件,我们需要多行的文本提示信息时,使用”\n”, “
“均不能实现换行功能;后来在一次无意中的操作,实现了placeholder的换行功能。

placeholder的属性值本身包含格式信息,但不能转义字符(如’\n’, ‘\t’),在编辑器中可直接使用回车实现placeholder的换行功能。如:


<textarea placeholder="If you were a teardrop;In my eye,
For fear of losing you,I would never cry.

And if the golden sun,Should cease to shine its light, \t\n
Just one smile from you,Would make my whole world bright."></textarea>


显示效果如下:




测试环境: Google Chrome, Version 40.0.2214.91 (64-bit)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐