在我的页面中,有很多超链接。我想用'uid'属性改变所有'a'是这样的:
<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
}
);}
答案 0 :(得分: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);
});
});
});
假设您希望每次都获得它,这意味着每个链接都有不同的uid,否则只需获取一次名称