简体   繁体   English

未捕获的SyntaxError:具有Scala的javascript中的无效或意外令牌

[英]Uncaught SyntaxError: Invalid or unexpected token in javascript with scala

Can anyone check my code? 谁能检查我的代码? I don't know what happend but I got Uncaught SyntaxError: Invalid or unexpected token at one of my templates. 我不知道发生了什么,但是我的模板之一Uncaught SyntaxError: Invalid or unexpected tokenUncaught SyntaxError: Invalid or unexpected token

<script type="text/javascript" nonce="templates-random-id">
@templates.map { t =>
    $('#template-@t.id').click(function() {
        document.getElementById('text').value = '@t.content';
    });
}</script>

I use it for loading a templates from database. 我用它来从数据库加载模板。

    @templates.map { t =>
<button type="button" class="btn btn-default" id="template-@t.id">@t.template_name</button>
}

What i got from the source in browser: 我从浏览器中获得的信息:

$('#template-17').click(function() {
            document.getElementById('text').value = 'blablabla blablablablablab lablablablabl ablablablablabla;';
        });

Edit: I will try change '@t.content' to @t.content with `. 编辑:我将尝试将'@t.content'更改为@t.content Maybe it will help. 也许会有所帮助。

This is probably because of @t.content which contains special symbols. 这可能是因为@t.content包含特殊符号。 This fix might apply to your problem as well Escape a JavaScript string in Play 2.0 view? 此修复程序也可能适用于您的问题在Play 2.0视图中转义JavaScript字符串? .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM