加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Ruby on Rails的文本字段中设置提示文本

发布时间:2020-12-17 03:19:49 所属栏目:百科 来源:网络整理
导读:有人可以建议在 Ruby on Rails中为文本字段设置提示文本(而不是默认文本)的最佳方法.目前我正在使用这个: %= text_field_with_auto_complete "customer",:contact_person,{ :value = 'last,first',:style = 'color:#aaa;width:11em;',:onfocus = "if(this.g
有人可以建议在 Ruby on Rails中为文本字段设置提示文本(而不是默认文本)的最佳方法.目前我正在使用这个:

<%= text_field_with_auto_complete
  "customer",:contact_person,{ 
    :value => 'last,first',:style => 'color:#aaa;width:11em;',:onfocus => "if(this.getValue()=='last,first'){this.clear();this.style.color = '#000';}",:onblur => "if(this.getValue()==''){this.setValue('last,first');this.style.color = #aaa';}" 
  } %>

文本字段附加到模型,然后附加到数据库中的值.此外,index.html中使用的相同html也在edit.html中使用,因此当我尝试编辑该字段时,默认值显示而不是数据库中的值.这样做的正确方法是什么?

注意:我不是要设置默认值,而只是提示需要在文本框中输入的内容.

谢谢,

拉贾拉姆

解决方法

我建议使用HTML 5占位符属性,然后使用jQuery插件使其在旧版浏览器上运行(如 this one,但有 are many others on Google).

你可以see this technique used in production here.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读