Jquery检查相关工作

时间:2015-11-03 10:16:37

标签: jquery css ajax

< p>我有一个关于rel属性的问题。< / p> < p>问题是来自以下行的if else语句:< / p> < pre>< code> if(REL ==' Like'){     // 做一点事    if($(" #love" + New_ID).attr(' rel'' UnLove')。attr(' title',& #39; UnLove')){       // 做一点事    } } < /代码>< /预> < p>当我点击.yes_button然后它正在检查REL =='是'而且我想检查< code> $(" #love" + New_ID).attr(' rel'' UnLove')。attr(&# 39;标题',' UnLove')< / code>但它不起作用。 < / p为H. < p>任何人都可以告诉我我需要做什么呢?< / p> < p>这是完整代码:< / p> < pre>< code> var count = 0;   $(' body')。on("点击",' .like_button',function(){     // $(本).closest(' .new_like_items')。子女()隐藏();     var dataid = $(this).attr(' data-id');     var id = $(this).closest(' .new_like')。attr(' id');     var class_name = $(this).find(" .icon-newL")。attr(" class");     class_name = class_name.replace(/ icon \ -newL \ s + / gi,"");     $(this).closest(" .new_like")。find(" .icon-lpn")。removeClass()。addClass(" icon-lpn" + class_name);     var count = 0;     var KEY = parseInt($(this).attr(" data"));     var ID = $(this).attr(" id");     if(KEY ==' 1'){       var sid = ID.split(/ likes | loves /);     } else {       var sid = ID.split(/ like | love /);     }     var New_ID = sid [1];     var REL = $(this).attr(" rel");     var URL = $ .base_url +' like_post.php&#39 ;;     var dataString =' msg_id =' + New_ID +'& rel =' + REL;     $就({       键入:" POST",       网址:网址       data:dataString,       cache:false,       成功:function(html){         if(html){             //喜欢开始           if(REL ==' Like'){             //计数++;             // $(" #likess" + New_ID).show(' slow');             if($(' #likess' + New_ID).css(' display')==' none'){$(" #likess&#34 ; + New_ID)。显示('慢'); }                $("#elikes" + New_ID)。显示('慢')。前置("< span id ='你" + New_ID +& #34;' class =' numcount bbc'>< div class =' icon-newL icon-like-new lpos' id =' clk&#34 ; + New_ID +"'>< / div>< div class =' lcl' id =' lcl" + New_ID +"& #39;>" + count +"< / div>< / span>");                $('#lcl' + New_ID).html(function(i,val){return val * 1 + 1});                $('#' + ID).html('< div class =" icon-newL icon-like-new">< / div>&# 39;)。attr(' rel',' UnLike')。attr(' title',' UnLike');             if($(" #love" + New_ID).attr(' rel'' UnLove')。attr(' title',& #39; UnLove')){                //计数 - ;                $(' #love' + New_ID).html('< div class =" icon-newL icon-love-new">< / div>&# 39;)。attr(' rel',#39; Love')。attr(' title',' Love');                $('#lco' + New_ID)。text(function(i,val){return val * 1-1});                // $("#love_count" + New_ID).hide('慢')。前置("< span id =' love_count" + New_ID +"' class =' numcount bbc'>< div class =' icon-newL icon-love-new lpos'>< / div> < div class =' lco' id =' lco" + New_ID +"'>" + count +"< / DIV>< /跨度>&#34);              }               $(' #like_count' + New_ID).show(' slow');           } else if(REL ==' UnLike'){                 // 做一点事             }           //喜欢完蛋         }       }     });     返回false;   }); < /代码>< /预> < p为H. HTML< / p为H. < pre>< code>< div class =" op-lw like_button"数据-ID =" 0" id ='喜欢<?php echo $ post_id;?>' rel ='<?php echo $ postL_status;?>' title ='<?php echo $ postL_status;?>'>< div class =" icon-newL icon-like-new">< / div> < / DIV> < div class =" op-lw like_button"数据-ID =" 1" id =' love<?php echo $ post_id;?>' rel ='<?php echo $ Lpost_status;?>' title ='<?php echo $ Lpost_status;?>'>< div class =" icon-newL icon-love-new">< / div> < / DIV> < /代码>< /预>

1 个答案:

答案 0 :(得分:1)

你确定你的意思不是:

if($("#love" + New_ID).attr('rel') == 'UnLove' && $("#love" + New_ID).attr('title') == 'UnLove'){
   //....
}