问题描述
我在 jsLint 中遇到以下错误:
导致错误的行:
document.cookie = name + "=" + value + expires + "; path=/";
我知道为什么会这样,但是我希望我的代码符合要求.
I get why this happens, but I would like my code to be compliant.
我该如何解决?
谢谢.
推荐答案
放置
/*jslint browser:true */
在函数正文的开头.或者,您也可以使用
in the beginning of the body of your function. Or, alternatively, you may use
/*global document: false */
JSLint用于检查任何javascript代码,并且document
全局对象并不处处存在,因此您必须手动告诉JSLint您的代码旨在在浏览器中执行,因此document
全局变量被定义为.例如,对于服务器端javascript,希望JSLint报告此错误.
JSLint is for the checking of any javascript code, and the document
global object does not exists everywhere, so you have to manually tell JSLint that your code is aimed to be executed in browser, and thus document
global variable is defined. For example, for server-side javascript it is expected for JSLint to report about this error.
这篇关于如何更正“在定义文档之前就使用了文档".使用Jslint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!