JQuery Multi网站预览

时间:2012-05-05 21:30:38

标签: jquery this each

我创建了一个处理URL的PHP​​脚本,并返回给定URL的Title,FirstImage和Description。 在我的网站中,我想用预览替换的所有链接都有“replacement_link”类。 我想这个功能应该可行,但它没有:

var $alinks = $('a.replaced_link');
$alinks.each(function(){
            $this=$(this);
            url = $this.attr('href');
                     $.ajax({
                            type:"GET",
                            url:"data.php?getlink="+url,
                            beforeSend: function(){
                                    $this.append('<img align=center src="images/loader_dark.gif">');
                            },
                            success: function(data){
                                    if (data) {
                                            $this.after(data);
                                            $this.remove();
                                    }
                            },
                            error: function(){
                                    $this.find('img').remove();
                            }
                    });

});

在单个链接上,它正常工作。如果有多个“a.replaced_link”,则所有前一个都保留旋转加载,只有最后一个保留第一个链接(!!!)。 如果我删除“$ this.remove()”,所有链接都将附加在最后一个a.replaced_link中! 我希望明确...... 似乎$ this不会被拆分为“.each”上的不同对象 怎么解决?

P.S。我想删除对象,因为我可能需要多次触发此函数...而且我不想重新加载每个URL

1 个答案:

答案 0 :(得分:1)

房子里有{p> Implicit global!说

var $this = $(this);

而不是

$this = $(this);

与url obv。相同。

相关问题