You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用jQuery获取嵌套div中带static类的元素ID集合

提取动态生成元素的ID数组(jQuery实现)

直接用jQuery的.map()结合.get()就能快速得到目标数组:

const idArray = $('#data').find('.static').map(function() {
  return this.id;
}).get();

说明

  • .map()遍历所有匹配的.static元素,逐个返回元素的id属性
  • .get()将jQuery封装的结果转换为原生JS数组,最终得到[line-plot, bar-plot]这样的格式

如果偏好原生JS写法,也可以这么做:

const staticElements = document.querySelectorAll('#data .static');
const idArray = Array.from(staticElements).map(el => el.id);

内容的提问来源于stack exchange,提问作者Gnani Kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 13:01:03