jquery每个函数

时间:2011-09-20 00:31:10

标签: jquery

我有一个从数据库调用的循环,每个循环都有一个具有唯一URL的链接。我正在使用模态脚本来加载div中的链接,但它只适用于第一个链接。从数据库调用的其他链接将不会在模式中打开。他们在新窗口打开。我怎样才能解决这个问题?我已经尝试过($('#ajax2')。each(function())但是没有用。

这是剧本。

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

1 个答案:

答案 0 :(得分:0)

修改您的功能,如下所示

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