2012-08-16 65 views
0

我有這個鏈接,點擊時會出現一個模式對話框。Modal對話框僅在點擊第一個鏈接後顯示

<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鏈接將出現在模式對話框,但如果我點擊任何鏈接除第一個鏈接外,該框不會出現。什麼似乎是我的代碼上的問題?謝謝。

回答

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 
}); 
+0

thanks.this works。:) – 2012-08-16 18:51:56

1

既然你沒有提供更多信息我就猜你的問題是,您可設置針對所有鏈接(addtoteam

相同idid必須是唯一的,所以你應該使用而不是類別選擇器

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

$('.addtoteam').click(function(event){....} 
+0

感謝這部作品:)。我怕我不能接受兩個答案吧?hehe – 2012-08-16 18:52:22

+1

@ChiRiLo;嘿,很高興幫助:) – 2012-08-16 19:03:31

相關問題