Jquery点击正在改变所有其他值! [英] Jquery click is changing the all other values!

查看:91
本文介绍了Jquery点击正在改变所有其他值!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Like Different按钮使用一些代码!问题是当我点击第一个Like链接然后所有span.count值改变。

I'm using a little code for Like Unlike button! Problem is when i click on first Like link then all span.count value change.

<script>
$(document).ready(function(){
$('a.like').click(function () {
    if ($(this).attr('class') == 'like') {
        $.post("like.cfm", {postid:$(this).attr("postid"),uid:$(this).attr("uid")} );
 
        $(this).removeClass('like').addClass('unlike').html('Unlike');
		var test=$('.count').html();
        test++;
        $(".count").html(test);
    } else {
        $.post("unlike.cfm", { pageID: $(this).attr("postid") });
 
        $(this).removeClass('unlike').addClass('like').html('Like');
		
		var test=$('span.count').html();
        test--;
        $(".count").html(test);
    }
});
});
</script>





这是HTML





Here's the HTML

<a href="##" class="like" postid="1234" uid="2">Like </a> <span class="count">100</span>
<br>
<br>
<a href="##" class="like" postid="1234" uid="2">Like </a> <span class="count">100</span>







JSFiddle http://jsfiddle.net/tgaQA/ [ ^ ]

推荐答案

document )。ready( function (){
(document).ready(function(){


' a.like')。click( function (){
if
('a.like').click(function () { if (


this )。attr(' class')== ' 喜欢'){
(this).attr('class') == 'like') {


这篇关于Jquery点击正在改变所有其他值!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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