今天我写了这段代码:
(function (window) {
'use strict';
function ViewPort() {
var getSize = function () {
var e = window,
a = 'inner';
if (!('innerWidth' in window)) {
a = 'client';
e = Document.documentElement || Document.body;
}
return { width : e[a + 'Width'], height : e[a + 'Height'] };
},
update = function () {
var vw = (getSize().width / 100);
Document.querySelector('html').style.fontSize = vw + 'px';
};
Document.addEventListener("resize", update());
}
function run() {
return new ViewPort();
}
window.viewport = run;
}(window));
window.onload = function () {
'use strict';
viewport();
};
当我使用 jshint 时,出现如下错误:
11 'Document' is not defined. (W117) e = Document.documentElement || Document.body;
19 'Document' is not defined. (W117) Document.querySelector('html').style.fontSize = vw + 'px';
22 'Document' is not defined. (W117) Document.addEventListener("resize", update());
30 'window' is not defined. (W117) }(window));
32 'window' is not defined. (W117) window.onload = function () {
34 'viewport' is not defined. (W117) viewport();
任何人都可以帮助我解决我的错误吗?我不知道如何修复它,scripts.js 文件中的这段代码不是内联的。
最佳答案
Javascript 区分大小写。 document
全部小写。那么它应该可以工作。
如果仍然不起作用,您可以尝试在文件开头添加一条指令,以暗示该脚本适用于浏览器,并且浏览器全局变量可用。
将此注释添加到脚本顶部:
/* jshint browser: true */
关于javascript 和 jshint,未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28193526/