首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ruby on rails-如何通过单击+按钮添加文本区域字段

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

Stack Overflow用户
提问于 2014-01-15 08:49:10
回答 1查看 2.8K关注 0票数 0

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

做这件事最简单的方法是什么?请我不是那么强大的JavaScript包括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 %>仅用于对表格中的问题进行编号。

EN

回答 1

Stack Overflow用户

发布于 2014-01-15 17:03:00

也许您可以从本教程http://rbudiharso.wordpress.com/2010/07/07/dynamically-add-and-remove-input-field-in-rails-without-javascript/中获得一些想法

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21127136

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档