2011-01-28 48 views
0

在我的頁面中,有許多超鏈接。我想改變所有的 'A' 與 'UID' 屬性是這樣的:С將所有用戶ID更改爲Facebook名稱

<a href=# uid="5526183">5526183</a> 

<a href=# uid="5526183">Afrig Aminuddin</a> 

另一個例子

<a href=# uid="5526183">My name is 5526183</a> 

<a href=# uid="5526183">My name is Afrig Aminuddin</a> 

首先:我會在'uid'處得到所有'a'標籤貢

var uid=$('a[uid]'); 

那麼我所說的功能,這個功能纔會被調用一次加載頁面...

named(uid); 

這裏是我的職責,

function named(uid){ 

// here i'd like to do something with the 'uid' array in order it can be 
// processed in the next line 

// in the next line, the 'uid' must be unique 
// so, before that i'd like to filter all the 'uid' array in order to 
// filter the double 'uid' 

FB.api(
    { 
    method: 'fql.query', 
    query: 'SELECT name FROM user WHERE uid IN (5526183,1000014057,100001491471735)' 
    }, 
    function(response) { 
    // change all the 'a' with 'uid' attribute here... 

    // response example 
    return response[0].name; //return the name of 5526183 
    return response[1].name; //return the name of 1000014057 
    return response[2].name; //return the name of 100001491471735 
    } 
);} 

任何幫助將真正理解...謝謝...... :)

回答

1
$(document).ready(function() { 
    var uid = $("a[uid]").eq(0).attr("uid"); 

    FB.api(
    { 
     method: 'fql.query', 
     query: 'SELECT name FROM user WHERE uid IN (' + uid + ')' 
    }, 
    function(response) { 
     $("a[uid]").each(function() { 
      var $this = $(this); 

      $this.text(response[0].name); 
     }); 
    }); 
}); 

,假設你想每次都得到它,這意味着你有每個鏈接不同的用戶名,否則只取一次名稱

+0

@ivanov:謝謝,但我必須重建我的功能,直到它工作... – theHack 2011-01-28 15:01:18