Ruby on rails 在RubyonRails的文本字段中设置提示文本
有人能建议在RubyonRails中为文本字段设置提示文本(而不是默认文本)的最佳方法吗。目前我使用的是:Ruby on rails 在RubyonRails的文本字段中设置提示文本,ruby-on-rails,textfield,hint,Ruby On Rails,Textfield,Hint,有人能建议在RubyonRails中为文本字段设置提示文本(而不是默认文本)的最佳方法吗。目前我使用的是: <%= text_field_with_auto_complete "customer", :contact_person, { :value => 'last, first', :style => 'color:#aaa;width:11em;', :onfocus => "if(this.getValue()=='last,
<%= 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';}"
} %>
“最后,第一”,
:style=>'颜色:#aaa;宽度:11em;',
:onfocus=>“如果(this.getValue()=='last,first'){this.clear();this.style.color='#000';}”,
:onblur=>“如果(this.getValue()=''){this.setValue('last,first');this.style.color=#aaa';}”
} %>
文本字段附着到模型,然后附着到数据库中的值。此外,index.html中使用的相同html也用于edit.html,因此当我尝试编辑字段时,会显示默认值,而不是数据库中的值。正确的方法是什么
注意:我不是试图设置默认值,只是提示需要在文本框中输入什么
谢谢
Raja Ram试试这个jquery插件
或选择此处:
原型
我建议使用HTML5
占位符
属性,然后使用jQuery插件使其在较旧的浏览器上工作(如,但有)
您可以。谢谢您的回复。但是在原型库中有类似的东西吗??我目前正在使用原型库。+1用于HTML5:)实际上大多数插件都是通过占位符属性工作的