SyntaxError:未终止的字符串文字javascript [英] SyntaxError: unterminated string literal javascript

查看:127
本文介绍了SyntaxError:未终止的字符串文字javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试在应用程序主页的部分添加以下两行时,我的浏览器都会出现JavaScript错误:

I am getting a JavaScript error in my browser whenever I am trying to add the following two lines in the section of my application home page:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="<%=request.getContextPath()%>/resources/jq/jquery-1.10.2.min.js"></script>')</script>

有人可以告诉我这两行有什么问题吗?并且如果可能的话如何解决它?

Can someone please tell me what is wrong in those two lines? and if possible how to fix it?

感谢您的时间

推荐答案

您无法在脚本块中的任何位置嵌入子字符串< / script>

You can't embed the substring </script> anywhere within a script block.

更改您的 document.write 致电:

<script>
  window.jQuery || 
  document.write('<script src="<%=request.getContextPath()%>/resources/jq/jquery-1.10.2.min.js"></' + 'script>')
</script>

浏览器解析< script> 通过盲目搜索结束< / script> 标记标记内容,不注意内容的语法。

The browser "parses" <script> tag contents by blindly searching for a closing </script> tag, paying no attention whatsoever to the syntax of the contents.

这篇关于SyntaxError:未终止的字符串文字javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆