小编Eth*_*cre的帖子

无法从 getElementsByClassName 访问 HTMLCollection 中的元素

我想从 HTMLCollection 中获取一个元素。document.getElementsByClassName 的返回正是我所期望的,但是当我尝试访问它的任何属性时,看起来那里什么也没有。这是我的代码(此代码在 .js 文件中运行,我将其 src 到我的 index.html 中):

document.addEventListener('DOMContentLoaded', function () {
    var code = document.getElementsByClassName('CodeMirror-code');
    console.log(code);
    console.log(code[0]); //undefined
    console.log(code.length); //0
}
Run Code Online (Sandbox Code Playgroud)

这是控制台日志:

HTMLCollection(1)
   0: div.CodeMirror-code        //this is the div I want to access
   length: 1
   __proto__: HTMLCollection
undefined
0
Run Code Online (Sandbox Code Playgroud)

另外,如果我在控制台中输入:

var code = document.getElementsByClassName('CodeMirror-code');
code[0]
Run Code Online (Sandbox Code Playgroud)

我得到回报:

<div class="CodeMirror-code">...</div>
Run Code Online (Sandbox Code Playgroud)

这正是我正在寻找的,但这不是我在脚本中得到的结果。

html javascript htmlcollection

5
推荐指数
1
解决办法
3031
查看次数

XCode没有打开组织者

我正在尝试将我的应用提交到应用商店.当我单击产品>存档时,它将完成存档的存档过程,但之后不会打开管理器屏幕.此外,当我单击窗口>管理器时,我的计算机切换桌面但不打开新窗口.为什么会发生这种情况,我该如何解决?

xcode ios

3
推荐指数
1
解决办法
2807
查看次数

标签 统计

html ×1

htmlcollection ×1

ios ×1

javascript ×1

xcode ×1