添加自定义类以形成字段 [英] Add custom class to form fields

查看:164
本文介绍了添加自定义类以形成字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有这种形式

 <%= form_tag'search',方法:'get',class:'form-水平'do%> 
<%= label_tag:搜索,'在此处输入网址'%>
<%= text_field_tag:search%>
<%= submit_tag'Get it!'%>
<%end%>

上面的代码增加了 class ='form-horizo​​ntal' class ='form-control 'b

解决方案

试试这个:

  text_field_tag:search,nil,class:'form-control'




以备参考:



  text_field_tag(name,value = nil,options = {})

text_field_tag:search
#=> < input id =searchname =searchtype =text/>

text_field_tag:搜索,'在此处输入您的搜索查询'
#=> < input id =searchname =searchtype =textvalue =在此输入您的搜索查询/>

text_field_tag:search,nil,class:'form-control'
#=> < input class =form-controlid =searchname =searchtype =text/>


Having such form

<%= form_tag 'search', method: 'get', class: 'form-horizontal' do %>
     <%= label_tag  :search, 'Enter url here' %>
     <%= text_field_tag :search  %>
     <%= submit_tag 'Get it!' %>
    <% end %>

Code above adds class='form-horizontal' for form tag.

How can I add class='form-control' for each input field ?

解决方案

Try this:

text_field_tag :search, nil, class: 'form-control'

For future reference:

text_field_tag(name, value = nil, options = {})

text_field_tag :search
# => <input id="search" name="search" type="text" />

text_field_tag :search, 'Enter your search query here'
# => <input id="search" name="search" type="text" value="Enter your search query here" />

text_field_tag :search, nil, class: 'form-control'
# => <input class="form-control" id="search" name="search" type="text" />

这篇关于添加自定义类以形成字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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