-2

我有这个:

HTML:

<div id="selectedsongs">
<a href="#" rel="1">song1></a>
<a href="#" rel="2">song2></a>
<a href="#" rel="3">song3></a>
</div>

然后:

selectedBtn = $('#selectedsong');

selectedBtn.click(function()
{
  self.selectedsong($('a', this).attr('rel'));
  return false;
});

但总是取第一个链接的 rel 值,在这种情况下,值为“1”。

为什么?:(

非常感谢你!;-)

4

2 回答 2

1

改为这样做:

<div id="selectedsongs">
<a href="#" rel="1">song1></a>
<a href="#" rel="2">song2></a>
<a href="#" rel="3">song3></a>
</div>

$('#selectedsongs a').click(function() {
   alert($(this).attr('rel'));
});

工作示例

于 2012-06-15T12:40:48.200 回答
1
$('#selectedsongs a').click(function() {
   selectedsong($(this).attr('rel'));
   return false;
});
于 2012-06-15T12:42:04.213 回答