1
我使用.live()中,即時通訊工作的網站,而現在看來,這不是運作良好,這是我的代碼:jQuery .live()問題,無法正常工作?
$('.comment_cheer').live("click",function(e){
e.preventDefault();
var id = $(this).attr('rel');
var url = $(this).attr('href');
var thisClass = this;
if(like2 == true){
like2 = false;
setTimeout(function(){
$.post(url,function(data){
$(thisClass).fadeOut('slow').fadeIn();
$(thisClass).removeClass('remove');
$(thisClass).addClass('add');
$('#boo_click_'+id).hide();
like2 = true;
});
},500);
}
return false;
});
我想要的是後,我發表評論,我可以選擇點擊在Cheer和Boo之間,當我點擊其中一個例如Cheer時,可點擊的Boo將消失以防止用戶點擊它,但是它不工作,我想讓它工作。有人能指導我在這裏嗎?
這裏是用我的歡呼和噓聲鏈接代碼IM:
<!--Cheer!-->
<span id="cheer_click_<?php echo $all_post['comment_id'];?>" class="add" rel="<?php echo $all_post['comment_id']?>">
<a href ="<?php echo base_url().'socket/likes/'.$all_post['comment_id']?>"
class ="comment_cheer"
rel ="<?php echo $all_post['comment_id']?>"
target ="num_likes_<?php echo $all_post['num_likes']?>"
><span><i class="cheer_icon button_icons_profile_13 padr5"></i>Cheer!</span></a>
</span>
<!--Boo!-->
<span id="boo_click_<?php echo $all_post['comment_id'];?>" class="remove red" rel="<?php echo $all_post['comment_id']?>">
<a href ="<?php echo base_url().'socket/unlike/'.$all_post['comment_id']?>"
class ="comment_boo"
rel ="<?php echo $all_post['comment_id']?>"
target ="num_boos_<?php echo $all_post['num_likes']?>"
><span><i class="cheer_icon button_icons_profile_14 padr5"></i>Boo!</span></a>
</span>
您不需要'$ .live',因爲點擊事件出現泡沫,而且您似乎沒有動態添加「.comment_cheer」元素。另外,'$ .live'已被棄用。最後,我沒有看到類'comment_cheer'的一個元素 –
不知道問題是什麼,但考慮移動到'on()',因爲'live()'基本被棄用,但它可能贏了不能解決您遇到的問題,並且由於我沒有閱讀流體PHP變量,因此很難說出發生了什麼事情! – adeneo
@JuanMendes,我編輯了我的帖子..看看, – bunsiChi