1

我在第 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" 但这也不起作用。

4

1 回答 1

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);
        })
    }
}
于 2018-06-21T22:28:03.940 回答