在启动我的应用程序的开始,我通过django模板变量获取变量,如下所示:
var my_variable = '{{ variable }}';
Run Code Online (Sandbox Code Playgroud)
但有时它需要多行并提供语法错误
var my_variable = "This should be a good variable;
But it isn't";
Run Code Online (Sandbox Code Playgroud)
怎么避免Uncaught SyntaxError: Unexpected token ILLEGAL?
你可以尝试这个解决方案
<script>
{% autoescape off %}
var my_variable = "{{ variable|escapejs }}"
{% endautoescape %}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
984 次 |
| 最近记录: |