2011-12-05 71 views

回答

1

未經測試,但試試這個:

對於#1:

$('a').each(function() { 

    var that = $(this); 
    var href = that.attr('href'); 

    if(href.search('yourdomain.com') != -1) {  
     that.attr('href', href+'?id=t'); 
    } 

}); 

對於#2:

$('a').filter(function() { 
    return this.hostname && this.hostname !== location.hostname; 
}).each(function() { 
    var rel = $(this).attr('rel'); 
    if(rel) { 
     $(this).attr('rel', rel + ' external'); 
    } else { 
     $(this).attr('rel', 'external'); 
    } 
}); 

$('a[rel*=external]').click(function() { 
    window.open(this.href); 
    return false; 
}); 
+0

謝謝。我會放棄並報告。 – TDave00

+0

完美的作品。謝謝。喜歡這個網站。 – TDave00

0

首先指定一個類 「入站」 所有入站鏈接和 「出站」 所有出站鏈接 $(文件)。就緒(函數(){

$('a.inbound').each(function(){ 
var h = $(this).attr('href'); 
$(this).attr('href',h+'?id=t'); 
}); 

$('a.outbound').attr('target','_blank'); 


}); 
+0

對不起,添加一個類並區分我的網站上的所有入站和出站鏈接是不現實的。謝謝。 – TDave00

相關問題