未捕获的SyntaxError:空行中有意外的标识符?

时间:2018-06-21 22:18:40

标签: javascript php syntax syntax-error unexpected-token

我在第40行收到语法错误...我不知道为什么,这个脚本也只能与所有其他文件一起使用(太多,无法上传)。它不是最好或最漂亮的,但请尝试一下。

错误:

  

未捕获的SyntaxError:意外的标识符

<?php
session_start();
?>

<!DOCTYPE html>

<html>
<head>
    <title>SCRABBLEGOD</title>
    <script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js'></script>
    <link rel="shortcut icon" type="image/png" href="favicon.png"/> 
</head>
<body>

<script type="text/javascript">
var row0 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row1 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row2 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row3 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row4 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row5 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row6 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row7 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row8 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row9 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row10 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row11 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row12 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row13 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var row14 = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
</script>

<img id="row0sm0" src=<?php echo "uploads/sm/" . $_SESSION["row0sm0"]; ?>>
<img id="row0sm1" src=<?php echo "uploads/sm/" . $_SESSION["row0sm1"]; ?>>
<img id="row0sm3" src=<?php echo "uploads/sm/" . $_SESSION["row0sm3"]; ?>>
<img id="row1sm0" src=<?php echo "uploads/sm/" . $_SESSION["row1sm0"]; ?>>
<img id="row2sm0" src=<?php echo "uploads/sm/" . $_SESSION["row2sm0"]; ?>>
<img id="row3sm6" src=<?php echo "uploads/sm/" . $_SESSION["row3sm6"]; ?>>

<script type="text/javascript">
var i;
var x;
for (i = 0; i < 15 i++) {
    for (x = 0; x < 15 i++) {
        Tesseract.recognize("row" + i + "sm" + x)
        .then(function(result){
            console.log(result.text);
            document.write(result.text);
        })
    }
}
</script>

</body>
</html>

这段代码是为拼字游戏机器人准备的,我已经使输入(来自上载文件的OCR)正常工作,但是不幸的是,由于语法错误,我似乎陷入了空白。我询问这可能是由于我使用的脚本类型引起的,我尝试使用type =“ module”,但这也不起作用。

1 个答案:

答案 0 :(得分:1)

for循环都缺少分号。

错误代码:

for (i = 0; i < 15 i++) {
    for (x = 0; x < 15 i++) {
        Tesseract.recognize("row" + i + "sm" + x)
        .then(function(result){
            console.log(result.text);
            document.write(result.text);
        })
    }
}

正确的代码:

for (i = 0; i < 15; i++) {
    for (x = 0; x < 15; i++) {
        Tesseract.recognize("row" + i + "sm" + x)
        .then(function(result){
            console.log(result.text);
            document.write(result.text);
        })
    }
}