【问题标题】:Change 2 images to one text onClick将 2 个图像更改为一个文本 onClick
【发布时间】:2014-04-30 00:15:02
【问题描述】:

当用户点击 thumbs_up 或 thumbs_down 时,这 2 个图标应替换为类似“您已投票”之类的文字。我该怎么做?

   <div class="thumbsup">
       <%= link_to image_tag('othericons/thumbsup_off.PNG', height: '20', width: '20', like_post_comment_path(comment.post_id, comment), method: :put, :remote => true %>
   </div>

    <div class="thumbsdown">
        <%= link_to image_tag('othericons/thumbsdown_off.PNG', height: '20', width: '20', dislike_post_comment_path(comment.post_id, comment), method: :put, :remote => true %>
    </div>

【问题讨论】:

  • 我可能会考虑使用 jQuery 追加?只需在图像上附加一个 div 或文本?

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


【解决方案1】:

将此添加到资产文件中

$('.thumbsdown a, .thumbsup a').on('click', function() {
  $('.thumbsdown').before('You voted')
  $('.thumbsdown, .thumbsup').remove()
})

这样做是在thumbsdown div 之前添加文本You voted,然后删除该div。没有唯一正确的方法可以做到这一点,所以这取决于你如何。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-29
    • 2023-03-03
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多