【问题标题】:rails form_for edit text arearails form_for 编辑文本区域
【发布时间】:2014-10-22 15:06:26
【问题描述】:

我想知道是否有办法在 form_for 中添加按钮,以便他们编辑 text_area。

<%= form_for(@post) do |f| %>
<div class="field
<%= f.label :content %><br>
<%= f.text_area :content, :size => "70x20" %>
</div>

这是我的 form_for 的一部分,我想添加一些带有 HTML 标签的按钮,这些按钮将在 text_area 中插入文本,如

<b></b> <i></i> 

有可能吗?谢谢。

【问题讨论】:

    标签: html ruby-on-rails erb form-for


    【解决方案1】:

    这是 javascript 的工作。有很多不同的资源可以在线查看。

    还有很多预建的。您可以查看(不分先后):

    在非常基本的 javascript 中,您可以执行以下操作:

    <%= link_to("Bold", '#', onclick: "myFunction(); return false") %>
    <script>
    function myFunction() {
      var textArea = document.getElementById('post_content');
      textArea.value += "<b></b>";
    }
    </script>
    

    【讨论】:

    • 你让我开心,先生!这正是我所需要的,我会投票,但由于我的声誉低,我不能投票,谢谢。
    猜你喜欢
    • 2015-07-31
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    相关资源
    最近更新 更多