如何在textarea中添加多行占位符文本? [英] How to add multi line place holder text in textarea?

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

问题描述

如何在textarea中添加多行占位符文本?.

How to add multi line place holder text in textarea? .

我得到了如下解决方案,但它在 mossilla、safari 中不起作用.

I got a solution like following but its not working im mossilla, safari.

Chrome 以这种方式工作..

Chrome works this way..

$('#nameTxtBox').attr("placeholder", "League Name \n 1-2 lines most designs");

推荐答案

不幸的是,作为一项规则,不支持多行占位符.Chrome 确实允许使用换行符,但跨平台支持可能参差不齐.推荐的做法是创建更短的单行占位符.如果你绝对需要一个多行占位符,你可以试试这个:

Unfortunately multi-line placeholders are not supported as a rule. Chrome does allow for newline characters, but support across platforms can be spotty. The recommended course of action would be to create shorter, single-line placeholders. If you absolutely need a multi-line placeholder, you can try this:

<textarea style='white-space:pre;' placeholder='Line 1

Line2'></textarea>

通过添加 css 属性 white-space:pre,您可以强制 textarea 将占位符文本视为预格式化文本.不过,支持也参差不齐.

By adding the css attribute white-space:pre, you force the textarea to treat the placeholder text as preformatted text. Again, though, support is spotty.

这篇关于如何在textarea中添加多行占位符文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆