HTML5的placeholder属性如何实现换行


在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>


显示效果如下:
placeholder显示效果

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM