Ruby on Rails:如何将占位符文本添加到 f.text_field? [英] Ruby on Rails: How do I add placeholder text to a f.text_field?

查看:49
本文介绍了Ruby on Rails:如何将占位符文本添加到 f.text_field?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 placeholder 文本添加到我的 f.text_field 字段,以便默认情况下预先编写文本,并且当用户在字段内单击时,文本消失 - 允许用户输入新文本?

How can I add placeholder text to my f.text_field fields so that the text comes pre-written by default, and when a user click inside the fields, the text goes away - allowing the user to type in the new text?

推荐答案

使用 rails >= 3.0,您可以简单地使用 placeholder 选项.

With rails >= 3.0, you can simply use the placeholder option.

f.text_field :attr, placeholder: "placeholder text"

这篇关于Ruby on Rails:如何将占位符文本添加到 f.text_field?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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