gpt4 book ai didi

javascript - jquery 错误 n 无效的选择器

转载 作者:行者123 更新时间:2023-11-29 23:35:08 24 4
gpt4 key购买 nike

我有那行代码:

  const actions = $('.leaflet-draw-actions a:visible').length;

这会引发很多错误:

DOMException: Failed to execute 'querySelectorAll' on 'Document': '.leaflet-draw-actions a:visible' is not a valid selector.
at Function.Sizzle [as find] (...\node_modules\jquery\dist\jquery.js:869:1)

我想选择 .leaflet-draw-actions div 的所有链接可见子项。

您知道更好的有效选择器吗?

最佳答案

来自官方文档:

Because :visible is a jQuery extension and not part of the CSS specification, queries using :visible cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. To achieve the best performance when using :visible to select elements, first select the elements using a pure CSS selector, then use .filter(":visible").

而且它显然会尝试调用 querySelectorAll

关于javascript - jquery 错误 n 无效的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46469021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com