Javascript TypeError ____ is not a function

后端 未结 4 1615
野性不改
野性不改 2021-01-27 02:46

I am currently using the Chrome console to do some debugging for a Greasemonkey script.

From the console I run var opp = document.querySelectorAll(\'a[class=\"F-re

4条回答
  •  伪装坚强ぢ
    2021-01-27 03:04

    Yes, this is because the result of querySelectorAll is a node list, not an array. You can apply the slice method of Array to a node list, however:

    Array.prototype.slice.call(op, 0, 1);
    

    This works more or less as expected, because a NodeList "quacks" in just the way slice expects, i.e. it contains elements indexed sequentially. However, you should be wary of using this in general; it is much safer to simply iterate over the NodeList.

提交回复
热议问题