2011-09-20 80 views
0

我有一個從數據庫調用的循環,每個循環都有一個具有唯一url的鏈接。我正在使用一個模式腳本來加載鏈接在一個div中,但它只會與第一個鏈接一起工作。數據庫中調用的其他鏈接將不會在模式中打開。他們在新窗口中打開。我怎樣才能解決這個問題?我試過($( '#ajax2')。每個(函數()),但不起作用。jQuery的每個功能

這裏的腳本。

if($totalRows_games>0) 
    { ?> 
    <a id="ajax2" title="Pending Challenge" href="FBaction.php?tid=<?php echo $tid?>"  onClick="self.location=this.href; return false">Action</a> <?php }} while ($row_games =  mysql_fetch_assoc($games)); ?><? }?> 

     $('#ajax2').click(function(){ 
     var url = $(this).attr('href'); //get the attribute href 
     var title = $(this).attr('title'); //get the attribute href 

     lightbox.alert({ 
     width: '400px', 
     title: title, 
     rightButtons: ['Close'], 
     background: 'none', 

     opened: function(){ 
      $('<span />').load(url).appendTo('#lbContent'); 
     }, 
     buttonClick: function(button){ 
      console.log(button); 
     } 
    }); 
    return false; 
}); 
+0

請問您能向我們展示瀏覽器實際看到的生成的HTML,而不是PHP頁面嗎? – jfriend00

+0

生成的HTML?我不確定你在問什麼 –

+0

瀏覽器看到的實際HTML。/Source在瀏覽器中並從那裏複製,即在PHP腳本被評估之後並轉化爲合法的HTML。你在這裏發佈的是被輸入到你的web服務器並轉換成一個實際的HTML頁面的PHP。 – jfriend00

回答

0

修改你的功能和如下

$('#ajax2').click(function(event){ 
     event.preventDefault(); 
    } 
+0

我試過這一個的每一個變體,它不工作 –

+0

我將它從「Id」更改爲「Class」,現在它工作正常 –