3
我想要使用語音識別API,所以我從簡單的頁面開始,點擊body元素開始識別。我scripts.js中的文件是:簡單腳本的「非法調用」錯誤
var recognition = new window.webkitSpeechRecognition();
document.body.addEventListener("click", recognition.start, false);
現在,當我點擊body元素上的任何地方我都在Chrome控制檯奇怪的錯誤:
Uncaught TypeError: Illegal invocation
它指的是我的HTML代碼第一道防線。我的HTML文件是:
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="scripts.js"></script>
</body>
</html>
我該如何解決這個奇怪的錯誤?
嘗試'document.body.onclick = recognition.start;'。 – Bird
不好,不幸的是,同樣的錯誤。 – 1valdis
嘗試'document.body.addEventListener(「click」,function(){recognition.start()},false);' –