2010-12-31 3 views
0

다음은 두 개의 jquery 코드입니다. 첫 번째 링크를 클릭하면 텍스트 메시지가 인쇄되고 두 번째 링크는 링크를 클릭하면 div가 아래로 이동합니다. 두 번째 코드를 첫 번째 코드와 병합하여 링크를 클릭하면 첫 번째 코드에서와 같이 메시지가 표시되고 두 번째 코드 에서처럼 #votebox가 아래로 슬라이드되어 콘텐츠가 표시됩니다. 나는 어떤 도움을 매우 감사 할 것입니다.두 개의 작은 jquery 코드 병합

$("a.vote_up").click(function(){ 

the_id = $(this).attr('id'); 
$("span#votes_count"+the_id).fadeOut("fast"); 
$.ajax({ 
     type: "POST", 
     data: "action=vote_up&id="+$(this).attr("id"), 
     url: "votes.php", 
     success: function(msg) 
     { 
      $("span#votes_up"+the_id).fadeOut(); 
      $("span#votes_up"+the_id).html(msg); 
      $("span#votes_up"+the_id).fadeIn(); 

      //Here, I want to slide down the votebox and content div (from code below). 

     } 
    }); 
}); 

다음 코드는 그 안에 votebox의 사업부 및 표시 내용을 슬라이드, 나는 위의 코드에서 그것을 포함 할. 어떤을위한

$("a.vote_up").click(function(){ 
var id=$(this).attr("id"); 
var name=$(this).attr("name"); 
var dataString = 'id='+ id + '&name='+ name; 
//I want to include this votebox in above code. 
$("#votebox").slideDown("slow"); 
$("#flash").fadeIn("slow"); 

$.ajax({ 
type: "POST", 
url: "rating.php", 
data: dataString, 
cache: false, 
success: function(html){ 
$("#flash").fadeOut("slow"); 
//and want to use this div as well. 
$("#content").html(html); 
} 
}); 
}); 

감사합니다 도움.

+0

마크 업을 게시하여 수행하려는 작업에 대한 컨텍스트를 가질 수 있습니까? – prodigitalson

답변

1

간단한 방법은 별도로 정의하는 것입니다. voteDown에 대한 기능과 성공 함수에서 호출 : 예컨대

$("a.vote_up").click(function(){ 

the_id = $(this).attr('id'); 
$("span#votes_count"+the_id).fadeOut("fast"); 
$.ajax({ 
     type: "POST", 
     data: "action=vote_up&id="+$(this).attr("id"), 
     url: "votes.php", 
     success: function(msg) 
     { 
      $("span#votes_up"+the_id).fadeOut(); 
      $("span#votes_up"+the_id).html(msg); 
      $("span#votes_up"+the_id).fadeIn(); 
         var that = this; 
      voteDown.call(that); 

     } 
    }); 
}); 




function voteDown() 
{ 
    var id=$(this).attr("id"); 
    var name=$(this).attr("name"); 
    var dataString = 'id='+ id + '&name='+ name; 
    $("#votebox").slideDown("slow"); 
    $("#flash").fadeIn("slow"); 

    $.ajax({ 
     type: "POST", 
     url: "rating.php", 
     data: dataString, 
     cache: false, 
     success: function(html){ 
      $("#flash").fadeOut("slow"); 
      //and want to use this div as well. 
      $("#content").html(html); 
     } 
    }); 
} 

편집 다음 JS Votedown에 대한 기능을 수정.

+0

답변을 주셔서 감사합니다, 그러나 그것은 작동하지 않습니다. 두 코드는 완벽하게 분리되어 작동하지만 결합하면 작동하지 않습니다 (인쇄도 슬라이드도 아닙니다). – Billa

+0

죄송합니다 .. voteDown 함수 정의에 오류가 있습니다. 그것을 정정했다. 지금 해봐. .. – Chandu