Jquery如果不工作; - > [英] Jquery if else not working ;->

查看:61
本文介绍了Jquery如果不工作; - >的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码



< script> 
$( document )。ready( function (){
$(< span class =code-string>' a.like')。click( function (){
var next = $( this )。next()
var test = $( this )。next()。html();
< span class =code-keyword> if ($( this )。attr('' class')== ' like'){
$ .post( like.cfm,{
postid:$( this )。attr( postid ),
uid:$( this )。attr( uid
});

$( this )。removeClass(' like')。addClass(' 与'不同).html(< span class =code-string>' 与')不同;

test ++;

} else if ($( this )。attr(' class')== ' 不同{
$ .post( different.cfm,{
pageID:$( this )。attr( postid
});

$( this )。removeClass(' 与'不同。)addClass(' like')。html(< span class =code-string>' 赞');

test--;
}
next.html(测试);
});
});
< / script>





这是html



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

< br $>




点击Like工作正常但当我点击时不会发生任何事情; - >

解决方案

document )。ready( function (){

' a.like')。click( function (){
var next =


)。next()
var test =


Here's the code

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



Here's the html

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




Clicking on Like is working well but when i click on Unlike nothing happens ;->

解决方案

(document).ready(function () {


('a.like').click(function () { var next =


(this).next() var test =


这篇关于Jquery如果不工作; - &gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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