Jquery 字符数没有显示在我的评论表单下,即使它们适用于我的其他表单。任何帮助表示赞赏。
_form.html.erb
<%= form_for [@commentable, @comment] do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_field :title %>
<div class="titlecountdown"></div>
<%= f.text_area :content %>
<div class="contentcountdown"></div>
</div>
<div class="actions">
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
</div>
<% end %>
custom.js.coffee
$ ->
updateTitleCountdown = ->
remaining = 20 - jQuery("#comment_title").val().length
jQuery(".titlecountdown").text remaining + " characters remaining"
jQuery ->
updateTitleCountdown()
$("#comment_title").change updateTitleCountdown
$("#comment_title").keyup updateTitleCountdown
$ ->
updateContentCountdown = ->
remaining = 120 - jQuery("#comment_content").val().length
jQuery(".contentcountdown").text remaining + " characters remaining"
jQuery ->
updateContentCountdown()
$("#comment_content").change updateContentCountdown
$("#comment_content").keyup updateContentCountdown