javascript - 如何使用父 ID 修改子 ID?
问题描述
对于某些背景,我有一组图表显示一个国家(例如英格兰)的数据。我希望能够更新所有这些图表以显示不同国家(例如苏格兰)的数据,只需按一下按钮。
我目前尝试这样做的方式是找到父 ID,然后更改子 ID(这似乎比执行 IF 语句检查子 ID 是什么然后更改它要快得多,因为有超过 20图表)。
到目前为止我的脚本:
document.getElementById("scotlandButton").onclick = function() {myFunction()};
function myFunction() {
$(document).find('#graph1-first-tab').find('#england_graph').attr('id', 'scotland_graph');
}
html示例:
<button id="scotlandButton">Scotland Data</button>
<div id="graph1-first-tab">
<canvas id="england_graph"></canvas>
</div>
这些图表的 ID 为“england_graph”和“scotland_graph”。
谢谢!
解决方案
推荐阅读
- bash - Git 签出失败,出现“非法字节序列”
- r - 使用 R 模拟 ARMA 模型
- python - 使用 scikit-learn 训练数据时,SVM 多类分类停止
- css - 合适的 CSS 显示以在每行中显示任意行数的 3 个项目?
- c++ - 我的单例中的数组在离开函数后没有保留信息,然后在尝试再次访问信息时崩溃
- swift - 带有 Xcode 11 beta 7 的 SwiftUI 未更新 List / ForEach 的内容
- c++ - 从底层类型安全地转换枚举类
- excel - 如何创建一个 excel VBA 循环以在单元格 A5、B4、C3、D2、E1 中打印文本(“x”)
- git - 如何使用包含“/”的个人访问令牌通过 https 进行 git clone?
- python - Python:将 x,y,z 数据转换为以 x,y 作为元组键的字典