var url = "C:\xampp\htdocs\wcf2\wcf/attachments/5d/18-5dffacdfe6d2cf1db8dfabbb5b53ae8dc65bd325";


结果为Uncaught SyntaxError: Unexpected token ILLEGAL。有什么办法可以在JavaScript中修复它,还是需要在PHP中对其进行转义?

编辑:我的脚本如下所示:

<script>
  window.onload = function() {
    thingiurlbase = "{@$__wcf->getPath('td')}js";
    thingiview = new Thingiview("viewer");
    thingiview.setObjectColor('#C0D8F0');

    thingiview.initScene();
    var url = "C:\\xampp\htdocs\\wcf2\\wcf/attachments/5d/18-5dffacdfe6d2cf1db8dfabbb5b53ae8dc65bd325";
    thingiview.loadSTL(url);
    thingiview.setRotation(false);
  }
</script>

最佳答案

您需要转义反斜杠字符。

var url = "C:\\xampp\\htdocs\\wcf2\\wcf/attachments/5d/18-5dffacdfe6d2cf1db8dfabbb5b53ae8dc65bd325";


否则,JavaScript尝试将\x\h\w解释为转义的特殊字符。

但是,在这种特殊情况下,看起来您可以将\替换为/

var url = "C:/xampp/htdocs/wcf2/wcf/attachments/5d/18-5dffacdfe6d2cf1db8dfabbb5b53ae8dc65bd325";

10-07 21:07