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