2013-07-01 5 views
0

jquery에 문제가 있습니다. 나는 여러 행이있는 테이블이 있습니다. 행 중 하나 (한 번만)를 클릭하면 jquery로 게시물을 보내야합니다. 문제는 이벤트가 모든 테이블 셀에 대해 발생하기 때문에 이것을 위해 one() 함수를 사용할 수 없다는 것입니다. 여기 코드입니다 :여러 테이블 셀에서 jQuery one() 함수 사용

 $("#tabel_notificari").one("click", ".rand_notif td:last-child" ,function(e){ 
     e.stopPropagation(); 
     var idNotif=$(this).parent().attr("record"); 
     $.post("../template/masa/gestionare_notificare.php",{id:idNotif, status:3}, function(data){ 
     $(this).parent().prev(".spacer_2").remove(); 
     $(this).parent().fadeOut(500);return true;}); 
    }); 

이 문제와 helpme 수 누구인가? 감사. 단지 클릭 코드 셀을 클릭하는 관계없이 한 번에 실행할 수

답변

2

클릭 이벤트 외부 변수를 사용하여 on 대신 one를 사용 ...

var clicked = false; 
$("#tabel_notificari").on("click", ".rand_notif td:last-child" ,function(e){ 
    e.stopPropagation(); 
    if (!clicked) { 
     clicked = true; 
     var idNotif = $(this).parent().attr("record"); 
     $.post("../template/masa/gestionare_notificare.php",{id:idNotif, status:3}, function(data){ 
      $(this).parent().prev(".spacer_2").remove(); 
      $(this).parent().fadeOut(500); 
      return true; 
     }); 
    } 
}); 

.

+0

나는 그것을 시험해 보았지만 one() 함수를 사용하는 다른 방법이 있습니까? –

+0

아니요. 선택기와 일치하는 모든 요소에 자체를 첨부하고 각각에 대해 한 번 실행합니다. – Archer

+0

그런 식이면 좋겠지 만 내 문제는 정반대입니다. 그것은 내 선택기와 일치하는 모든 요소에 자체를 첨부하고 모든 요소에 대해 한 번 실행됩니다. –