dongmu5246
2015-04-17 13:08
浏览 82
已采纳

刷新具有相同id的许多div onclick href中的特定div id

I want to display like count for that post the user likes, every post like href has a specific id, now if I am clicking the post having id 222. Then like count having id 222 will refresh.

<a href="" onclick="rate('111');">like</a> <div id="111">4</div>
<a href="" onclick="rate('222');">like</a> <div id="222">5</div>
<a href="" onclick="rate('333');">like</a> <div id="333">12</div>

My rate function

<script type="text/javascript">
function rate(c) 
{   
        var c   
    jQuery.ajax({
        type: 'POST',
        url: 'rate.php',
        data: {
                cmnt: c     
               }
         });  
          return false; 
}
</script>

the C variable is getting the post id

图片转代码服务由CSDN问答提供 功能建议

我想显示用户喜欢的帖子的计数,每个帖子如href都有一个特定的id,现在如果 我点击了id为222的帖子。然后就像ID 222那样刷新。

 &lt; a href =“”onclick =“rate('111');”  &GT;像&LT; / A&GT;  &lt; div id =“111”&gt; 4&lt; / div&gt; 
&lt; a href =“”onclick =“rate('222');”&gt; like&lt; / a&gt;  &lt; div id =“222”&gt; 5&lt; / div&gt; 
&lt; a href =“”onclick =“rate('333');”&gt; like&lt; / a&gt;  &lt; div id =“333”&gt; 12&lt; / div&gt; 
   
 
 

我的费率函数

 &lt  ; script type =“text / javascript”&gt; 
function rate(c)
 {
 var c 
 jQuery.ajax({
 type:'POST',
 url:'rate.php',
  n data:{
 cmnt:c 
} 
});  
返回false;  
} 
&lt; / script&gt; 
   
 
 

C变量获取帖子ID

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doucong1268 2015-04-17 13:16
    已采纳

    you can update your rate() function as given below

    <script type="text/javascript">
        function rate(c) 
        {   
            jQuery.ajax({
                type: 'POST',
                url: 'rate.php',
                data: {cmnt: c},
                success: function(html) {
                    var count = $("#"+c).html();
                    var new_count = parseInt(count)+parseInt(1)
                    $("#"+c).html(new_count);
                 }
                 });  
                  return false; 
        }
        </script>
    

    let me know if that helped you...

    打赏 评论

相关推荐 更多相似问题