2010-12-31 6 views
0

次の2つのjqueryコードがあります。最初はリンクをクリックするとテキストメッセージを表示し、2番目のリンクはリンクをクリックするとdivをスクロールします。 2番目のコードを最初のコードにマージしたいので、リンクをクリックするとメッセージが表示され、2番目のコードでは#voteboxがスライドしてコンテンツが表示されます。 は、私は任意の助けのために非常に感謝してます。2つの小さな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 divのと表示内容を滑り落ちる。

$("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

関連する問題