br0*_*00x 11 html javascript firefox getelementsbyclassname
我有几个div class='class_name',也已经声明了
var A = document.getElementsByClassName('class_name');
console.log(A[0]);
Run Code Online (Sandbox Code Playgroud)
Chrome控制台显示:
<div class="class_name"> div 1 </div>
Run Code Online (Sandbox Code Playgroud)
Firefox控制台显示:
<unavailable>
Run Code Online (Sandbox Code Playgroud)
问题是什么或可能的原因是什么?
有两种解决方案:
(1)console.log(JSON.stringify(variable, null, 4))代替使用console.info(variable).这具有捕获由任何类型的内存管理错误引起的错误的额外优势(并且出于这个原因通常建议仅通过console.info()).(注意:对DOM元素变量不起作用,因为这会导致循环的无限递归错误.)
(2)卸载FireFox Quantum.我卸载了Firefox 57和59("Firefox Quantum"),然后安装了Firefox版本56.0.2.这解决了我的问题.在此处获取:https://ftp.mozilla.org/pub/firefox/releases/56.0.2/
根据原始问题的日期,它不是特定的版本57导致了这个问题(因为它尚未发布).但这是我的解决方案.
Firefox开发票证:https://bugzilla.mozilla.org/show_bug.cgi? id = 1136995
更新: Firefox v.59.0.2仍然存在问题.
两种可能的解决方法:
1)使用“ Web控制台”。
“ Web控制台”(而不是“ Browser-Console”)显示了预期的输出。
2)禁用“ e10s”多处理器支持:
- about:config
- browser.tabs.remote.autostart = False
Run Code Online (Sandbox Code Playgroud)
如果禁用了e10s,则浏览器控制台将显示预期的输出。
在FF 64.0
中,问题仍然存在:通常,在浏览器控制台中,对象将显示为“不可用”。
要重现(启用e10s):
<html><head>
<script type="text/javascript">
console.log( 'test' );
console.log( 123 );
console.log( [ 1, 2, 3 ] );
console.log( { x: 'x' } );
console.log( document.getElementById('myDiv') );
window.onload = function() {
console.log( document.getElementById('myDiv') );
};
</script>
</head><body>
<div id="myDiv"></div>
</body></html>
Run Code Online (Sandbox Code Playgroud)
在浏览器控制台中输出(错误的输出):
test
123
<unavailable>
<unavailable>
null
<unavailable>
Run Code Online (Sandbox Code Playgroud)
Web控制台中的输出(按预期):
test
123
Array(3) [ 1, 2, 3 ]
Object { x: "x" }
null
<div id="myDiv">
Run Code Online (Sandbox Code Playgroud)
另请参阅:https : //bugzilla.mozilla.org/show_bug.cgi?id=1136995
| 归档时间: |
|
| 查看次数: |
3169 次 |
| 最近记录: |