如何将XHTML rel attr传递给jQuery函数
我有一个URL,其中包含一个需要传递给jQuery函数的“rel”属性 以下是网址:如何将XHTML rel attr传递给jQuery函数,jquery,function,xhtml,rel,Jquery,Function,Xhtml,Rel,我有一个URL,其中包含一个需要传递给jQuery函数的“rel”属性 以下是网址: <a href="http://www.facebook.com/<?php echo $fblikeId; ?>" rel="<?php echo $fblikeId; ?>" ></a> 上述函数的“userid”参数需要检索“rel”标记的值。然后,上述函数将所有数据传递到一个更高的jQuery函数,该函数工作正常 检索链接的“rel”属性的最佳方法是什么
<a href="http://www.facebook.com/<?php echo $fblikeId; ?>" rel="<?php echo $fblikeId; ?>" ></a>
上述函数的“userid
”参数需要检索“rel
”标记的值。然后,上述函数将所有数据传递到一个更高的jQuery函数,该函数工作正常
检索链接的“rel”属性的最佳方法是什么?已尝试使用“$(this).attr('rel')
”,但不起作用
上述函数有多个节点。可能有多个电话
jQuery(function($) {
$('#fblikes').advancedsocialstatus({
'displayId':'fblikes',
'service':'facebook',
'countof':'likes',
'userid':$(this).attr('rel'),
'callback':'formatCount'
});
$('#fbtalks').advancedsocialstatus({
'service':'facebook',
'countof':'talks',
'userid':'$(this).attr('rel')',
'callback':'formatCount'
});
});
您不能在插件函数的选项对象中任意使用$(this)
。但是,您已经知道该元素,因此不需要此
;只需使用相同的选择器
var $fblikes=$('#fblikes');
$fblikes.advancedsocialstatus({
'displayId':'fblikes',
'service':'facebook',
'countof':'likes',
'userid': $fblikes.attr('rel'),
'callback':'formatCount'
});
此代码假定
$(“#fblikes”)
用于显示的
标记,但该html中没有ID
,上面链接中的ID只是更新了URL以包含ID标记。这绝对是一种享受。谢谢你的及时回复。谢谢。
var $fblikes=$('#fblikes');
$fblikes.advancedsocialstatus({
'displayId':'fblikes',
'service':'facebook',
'countof':'likes',
'userid': $fblikes.attr('rel'),
'callback':'formatCount'
});