手记

老菜鸟 rails笔记 动态给form_tag中的元素的name属性赋值

<table width="100%" align="center" cellpadding="0" cellspacing="0" class="table" id="date_table">
<%  @mplan.each do |day| %>
    <% if day.saturday? || day.sunday? %>
        <tr id="w<%= day %>" class="weekend">
            <td class="eheader" >考勤日期:</td>
            <td ><input id="<%= day %>" name="<%= day %>" type="date" value="<%= day%>" ></td>
            <td class="eheader" >考勤班组:</td>
            <td ><%= select_tag  "shift#{day}" ,options_from_collection_for_select(@shifts,"id","shift"),:class => "text_input shift",:id =>"shift"+day.to_s %>
            </td>
        </tr>
    <% else %>
        <tr id="r<%= day %>">
            <td class="eheader" >考勤日期:</td>
            <td ><input id="<%= day %>" name="<%= day %>" type="date" value="<%= day%>" ></td>
            <td class="eheader" >考勤班组:</td>
            <td ><%= select_tag  "shift#{day}",options_from_collection_for_select(@shifts,"id","shift"),:class => "text_input shift",:id =>"shift"+day.to_s %>
            </td>
        </tr>
    <% end %>
<%end%>
</table>
关键代码 select_tag  "shift#{day}" 其中day是循环的变量。
0人推荐
随时随地看视频
慕课网APP