[英]ruby on rails- how to add a text-area field by clicking a + button
我有一個簡單的表格,有5個問題(文本區域)供用戶填寫。 我希望用戶能夠通過單擊“加號”按鈕來添加其他問題。
最簡單的方法是什么? 請我在包括jQuery在內的JavaScript中不太熟練,所以請提供一些清晰的代碼,如果可能的話,請少做解釋。
這是我的看法:
<% 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 %>
僅用於將問題編號為表格形式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.