ruby on rails-如何通过单击+按钮添加文本区域字段

时间:2014-01-15 00:49:10

标签: javascript jquery ruby-on-rails ruby-on-rails-4 erb

我有这个简单的表格,有5个问题(文本区域)供用户填写。我希望用户能够通过单击“加号”按钮添加额外的问题。

最简单的方法是什么?请问我在JavaScript中不是很强大,包括jQuery,所以我会请求一些明确的代码,如果可能的话,很少解释。

这是我的观点:

<% question_numbering = 0 %>
<%= simple_form_for(@quiz, html: {class: 'form-vertical', id: 'someform' }) do |f| %>

    <div>
        question <%= question_numbering += 1 %><br>
        <%= f.input_field :content, :rows => 3, :style => "width:80%", :placeholder => "enter your question."  %><br>
        question <%= question_numbering += 1 %><br>
        <%= f.input_field :content, :rows => 3, :style => "width:80%", :placeholder => "enter your question."  %><br>
        question <%= question_numbering += 1 %><br>
        <%= f.input_field :content, :rows => 3, :style => "width:80%", :placeholder => "enter your question."  %><br>
        question <%= question_numbering += 1 %><br>
        <%= f.input_field :content, :rows => 3, :style => "width:80%", :placeholder => "enter your question."  %><br>
        question <%= question_numbering += 1 %><br>
        <%= f.input_field :content, :placeholder => "enter your question."  %><br>
    </div>

    <button type="button" class="btn btn-default" id = "js-add-question-row">
        <span class="glyphicon glyphicon-plus"></span>
    </button>
    <%= f.submit 'Submit', :class => "btn btn-default" %>
<% end %>

请注意question <%= question_numbering += 1 %>仅用于对表格中的问题进行编号。

1 个答案:

答案 0 :(得分:1)