我在控制台Google中使用jQuery .attr:“不是函数”

时间:2019-04-25 09:18:19

标签: javascript jquery

我希望从here恢复第一封邮件的数据。 我正在使用$('#inboxtbl tbody tr').attr('data-id') 在Google Chrome控制台中,出现以下错误

Uncaught TypeError: $(...).attr is not a function at <anonymous>:1:25

谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

除非您在要调试的页面上加载了jQuery,否则Chrome devtools控制台中的$不是jQuery,它实际上是document.querySelector(或Element#querySelector的快捷方式您提供第二个参数)。因此,您将使用getAttribute,而不是attr

$('#inboxtbl tbody tr').getAttribute('data-id')

({$$实际上也是document.querySelectorAll的快捷方式,[或者如果提供第二个参数,则是Element#querySelectorAll。完整列表是here。)