我正在处理这部分代码:<div class="tabs-buttons-container"> <button class="tabs-button" onclick="openTabs(event, 'test11', 'red')">Tab 1</button> <button class="tabs-button" onclick="openTabs(event, 'test12')">Tab 2</button> <button class="tabs-button" onclick="openTabs(event, 'test13')">Tab 3</button> <span class="test"></span> <span class="red"></span> <span class="white"></span> </div>const openTabs = (event, tab, test) => { let i, tabContent, tabButton; tabContent = document.getElementsByClassName("tabs-content") for (i = 0; i < tabContent.length; i++) { tabContent[i].style.display = "none"; } document.getElementById(tab).style.display = "block"; document.getElementsByClassName(test).style.display = "block";}我当前的目标是将“red”类传递到函数中并更改 span 元素的显示。当我使用 ID 时,它工作正常,但当我想传递类时,结果为 null。是否可以在 JS 函数中动态传递类名?
- 2 回答
- 0 关注
- 91 浏览
添加回答
举报
0/150
提交
取消