[英]JavaScript Error: document is not defined. [no-undef]
我是 Web 开发的新手,所以我正在尝试学习 JavaScript,但我总是遇到此错误。
代码:
var myImage = document.querySelector('img');
myImage.onclick = function () {
var mySrc = myImage.getAttribute('src');
if (mySrc === 'images/old-big-garage.png') {
myImage.setAttribute('src', 'images/name1.png');
} else {
myImage.setAttribute('src', 'images/old-big-garage.png');
}
}
错误:
JSLint (4)
4 Missing 'use strict' statement. var mySrc = myImage.getAttribute('src');
6 Expected 'myImage' at column 9, not column 7. myImage.setAttribute('src', 'images/papst.png');
8 Expected 'myImage' at column 9, not column 7. myImage.setAttribute('src', 'images/old-big-garage.png');
10 Expected ';' and instead saw '(end)'. }
ESLint (1)
1 ERROR: 'document' is not defined. [no-undef] var myImage = document.querySelector('img');
问题在于 linter:ESlint。 尝试安装括号内: File ->Extension Manager-> bracketeslint
。 完成后, Debug -> Reload with Extension ( F5 )
。
如果需要,您可以禁用JSlint
。 这样你就不会收到恼人的警告。
希望这会奏效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.