Type error: Invalid invocation

Type error: Invalid invocation

scope.width = element[0].getBoundingClientRect();

抛出以下错误

TypeError: 'get x' called on an object that does not implement interface DOMRect. error in firefox and Invalid invocation in chrome

谁能给我解释一下这是什么?

简单,Element.getBoundingClientRect()

是一个方法,它是 DOMRect 接口的一部分。为了使用它,您必须在实现 DOMRect 接口的元素上调用它,即Canvas。

您选择的选定元素(在本例中为 DropDown)未实现 DOMRect 接口,因此无法使用它的方法 getBoundingClientRect

因此错误:

ypeError: 'get x' called on an object that does not implement interface DOMRect. error in firefox and Invalid invocation in chrome

您不能在下拉菜单上使用此方法,除非您修改不推荐的原型。