如何使用JavaScript将ID添加到多个元素? [英] How to use JavaScript to add IDs to multiple elements?

查看:51
本文介绍了如何使用JavaScript将ID添加到多个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找出解决问题的方法。通过激烈的几天研究,我得出结论,这个堆栈溢出问题是类似的,可能是一个解决方案(http://stackoverflow.com/questions/14408891/getelementbyid-multiple-ids),但我的所有试验我仍然可以'似乎实现了我的代码的解决方案。 http://codepen.io/anon/pen/BNvobY [< a href =http://codepen.io/anon/pen/BNvobYtarget =_ blanktitle =New Window> ^ ]。我已经多次提出同样的问题,但是我仍然会得到一些从来没有帮助的广泛答案。 **我的问题是**,如何从脚本创建多个ID来执行几个开放式过渡?



***虽然我特意想出来了。***

I cannot seem to figure out the solution to my problem. Through intense several days of research I've concluded this stack overflow question is similar and may be a solution (http://stackoverflow.com/questions/14408891/getelementbyid-multiple-ids), but with all my trials I still can't seem to implement the solution to my code. http://codepen.io/anon/pen/BNvobY[^]. I've asked the same question many times with variations, but I still keep getting broad answers that never help at all. **My question is**, How can I create multiple ID'S from the script to perform several open-transitons?

***Though I figured out specifically.***

var bodyEl = document.body,
content = document.querySelector('.content-wrap'),
openbtn = document.getElementById('open-button'),
closebtn = document.getElementById('close-button'),
isOpen = false;



它们是两个按钮,显示为如果向结果屏幕中间滚动,则会出现三个灰点。第一组灰点将打开两个黑盒子。 **我不要那个**。我只会**像第一组灰色点**只**打开第一个盒子,第二组灰色点**只**打开第二个盒子,依此类推。



我认为这部分javascript是为了实现这一点需要改变的,尽管我之前说过我似乎无法实现解决方案。一些**非常聪明的头脑**可以帮我解决这个问题!请不要提出建议!只是一个解决问题的直接答案!


They are two buttons shown as three gray dots if you scroll towards the middle of the result screen. The first set of gray dots will open two black boxes. **I do not want that**. I would **only** like the first set of gray dots to **only** open the first box, the second set of gray dots to **only** open the second box, and so on.

I figured this portion of the javascript was what was needed to be altered in order to achieve this, though like I said before I cannot seem to implement the solution. Can some **very bright mind** help me figure this out! no advice please!, just a straight forward answer which solves the problem!

推荐答案

看看你提供的链接,那里有一个微小但严重的问题...

两个按钮元素都有相同的 - 'open-button' - ID ...在HTML中,每个元素必须具有不同的ID,甚至某些浏览器不强制执行此规则,您将遇到一些意外行为多个ID ...

修复很明显 - 使用唯一ID ......
Looking at the link you provided there is a tiny but serious problem there...
Both button elements has the same - 'open-button' - ID...In HTML every element must have different ID, and even some browsers do not force this rule, you will have some unexpected behavior with multiple IDs...
The fix is obvious - use unique IDs...


这篇关于如何使用JavaScript将ID添加到多个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆