代码之家  ›  专栏  ›  技术社区  ›  nnyby

Rails中的textarea字符计数

  •  0
  • nnyby  · 技术社区  · 15 年前

    我想用 observe_field 给我文本区域的字符数,在你输入时更新。我做错什么了?

    <div class="field">
      <%= observe_field :micropost_content,
          :function => "$('micropost_content').value.length" %>
      <%= f.text_area :content %>
    </div>
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   jdeseno    15 年前

    如果不设置频率选项,它将变为基于事件(onchange.),请尝试:

    <%= observe_field :micropost_content, :frequency => 1,
          :function => "$('micropost_content').value.length" %>