0

このリンクがあり、クリックするとモーダルダイアログボックスが表示されます。

<a href="#" id="addtoteam">
    Add to Team
</a>

これは、リンクをクリックした後に表示されるダイアログボックスです。

$('#addtoteam').click(function(event){
      event.preventDefault();
      var url = '<?php echo BASEURL;?>';
      var teamID = '<?php echo $_SESSION['User']['Team']['id']?>';
      var playerID = $(this).attr('player-id');
      $( "#dialogbox" ).dialog({ 
        autoOpen: true,
        buttons: { 
                  "Use Registration Credits": function(){ 
                    // execute something here before redirecting it to another page, perhaps perform the updating of the registration_credits of each team here
                    window.location = url + '/administration/add_to_team/' + playerID +'/'+ teamID +'/?credit=1'; 
                  },
                  "Pay Extra Charge": function() { 
                  //$(this).dialog("close"); 
                    window.location = url + '/administration/add_to_team/' + playerID +'/'+ teamID +'/?proceed=1';
                  },
                  "Cancel": function() { $(this).dialog("close"); } 
                },
        width: 800
      });
    });

これは機能していますが、最初のリンクでのみ機能します。私のリンクはリストです。すべての行に次のようなリンクがあります。

`abc| def| ghi| Add to Teamlink`
`123| 456" 789| Add to Team link` and so on.

リンクをクリックするabc| def| ghi| Add to Team linkとモーダルダイアログボックスが表示されますが、最初のリンク以外のリンクをクリックしてもボックスが表示されないのが気になります。私のコードの問題は何だと思われますか?ありがとう。

4

2 に答える 2

1

あなたはそれ以上の情報を提供していないので、あなたの問題はあなたがidすべてのリンクに同じように設定していることだと思います(addtoteam

id一意である必要があるため、代わりにクラスセレクターを使用する必要があります

<a href="#" class="addtoteam">
    Add to Team
</a>

$('.addtoteam').click(function(event){....}
于 2012-08-16T18:48:46.010 に答える
1

すべての[チームに追加]リンクを選択するには、IDの代わりにクラス名を使用する必要があります。

<a href="#" class="addtoteam">
    Add to Team
</a>

<a href="#" class="addtoteam">
    Add to Team
</a>

<a href="#" class="addtoteam">
    Add to Team
</a>

JS:

$('.addtoteam').click(function(event){
    //code
});
于 2012-08-16T18:48:47.623 に答える