【发布时间】:2018-04-24 04:47:08
【问题描述】:
我想知道为什么我的脚本可以在 Firefox 上运行,但不能在 google chrome 上运行
JS:
var _timelineWidth = (Number.parseInt(document.styleSheets[0].cssRules[16].style.width) / 100) * document.body.clientWidth;
CSS:
#timeline {
position: relative;
top: 15px;
left: 12.5%;
height: 5px;
background: #aaa;
border-radius: 2.5px;
cursor: pointer;
}
这是来自 chrome 的错误代码
未捕获的 DOMException:无法从 'CSSStyleSheet': 无法访问规则
【问题讨论】:
-
您引用的数组索引可能不在列表中。请检查
-
应该改用
getComputedStyle。