将2个图像更改为一个文本onClick [英] Change 2 images to one text onClick

查看:83
本文介绍了将2个图像更改为一个文本onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击thumbs_up或thumbs_down时,这两个图标应替换,并带有您投票等文字。我该怎么做?

When a user clicks on either thumbs_up or thumbs_down, those 2 icons should be replaced with a text like 'You voted'. How do I do that?

   <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>


推荐答案

在资产档案中添加

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

这样做是在 thumbsdown div之前添加文本您投票然后删除之后的div。没有一种正确的方法可以做到这一点,所以它就是这样你怎么做。

What this does is add the text You voted before the thumbsdown div and then remove the div afterwards. There's no single right way to do this so it's up to you how.

这篇关于将2个图像更改为一个文本onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆