<script>标记未正确关闭

Pyt*_*hos 3 javascript jquery jsp spring-mvc spring-roo

在我的default.jspx中,它包含页面的基本布局,我试图导入一些jquery库,如下所示

<head>
    ...
    <spring:url value="/resources/js/lib/jquery-1.9.1.min.js" var="jquery_url" />
    <spring:url value="/resources/js/lib/jquery.tokeninput.js" var="jquery_tokeninput_url" />
    <script src="${jquery_url}" type="text/javascript"></script>    
    <script src="${jquery_tokeninput_url}" type="text/javascript"></script>
    <script type="text/javascript">
        $.noConflict();
    </script>
    <util:load-scripts />
    ...
</head>
Run Code Online (Sandbox Code Playgroud)

但是当页面在浏览器中呈现时,第一个脚本标记会吞下另外两个脚本标记

<head>
...
<script type="text/javascript" src="/roo-inari/resources/js/lib/jquery-1.9.1.min.js">
//These lines are inside the first script tag
<script type="text/javascript" src="/roo-inari/resources/js/lib/jquery.tokeninput.js"/>
<script type="text/javascript">
        $.noConflict();
//The tag is closed here
</script>
<link href="/roo-inari/resources/dijit/themes/tundra/tundra.css" type="text/css" rel="stylesheet">
...
Run Code Online (Sandbox Code Playgroud)

知道可能导致这种情况的原因吗?该项目基于spring roo生成的web mvc脚手架.我使用的是Chrome v.25.

Pyt*_*hos 6

简单的解决方案是在标记内写一条注释,以便它不会自动关闭.傻我

<script src="${jquery_url}" type="text/javascript"><!-- required for some browsers --></script> 
Run Code Online (Sandbox Code Playgroud)

  • +1因为这听起来像具有类似问题的未来用户可能会发现有用.一旦SO允许您,也将此答案标记为已接受. (2认同)