0

我的页面上有几篇文章,一次只有一篇文章class="playing"。这取决于用户交互。因此,我需要以某种方式检查用户何时单击或执行类似操作,我需要找到带有 class="playing" 的文章并在全局变量中获取它的 id。

我试过这个,但它似乎不起作用

$(document).on("click", function() {
    nowPlaying = $('article').hasClass('playing');
    nowPlaying = nowPlaying.atrr('id');
});

每次单击时,我都会在控制台中收到此错误:

TypeError: 'undefined' is not a function (evaluating 'nowPlaying.atrr('id')')
4

1 回答 1

2

atrr不是函数的名称;改用attr

此外,您可以像这样缩短代码:

nowPlaying = $('article.playing').attr('id');
于 2013-06-12T00:29:18.977 回答