【问题标题】:ruby on rails- how to add a text-area field by clicking a + buttonruby on rails-如何通过单击 + 按钮添加文本区域字段
【发布时间】:2014-01-15 00:49:10
【问题描述】:

我有一个简单的表格,有 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 &lt;%= question_numbering += 1 %&gt; 仅用于对表格中的问题进行编号。

【问题讨论】:

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


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 2014-06-20
  • 2018-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多