JSLint将无法识别getElementById

时间:2015-06-23 15:36:17

标签: javascript function getelementbyid jslint

JSLint使用简单的函数提供错误,使用JSLint在括号上运行。

使用Javascript:

function soundSorry() {
    getElementById("player").play();
} 

错误代码:

2   Missing 'use strict' statement. getElementById("player").play();
2   'getElementById' was used before it was defined. getElementById("player").play();

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

您错过了document前缀。在document对象上定义getElementById时,您需要使用document对象调用它,如下所示:

document.getElementById("player").play();
// ^^^^^^

Docs