我的页面上有几篇文章,一次只有一篇文章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')')