在JSPX文件中包含JS文件(JQuery) [英] Including JS files (JQuery) in JSPX files
问题描述
我正在Eclipse中创建一个动态Web项目(几乎从头开始),我创建了一个JSPX文件,其中我放了
I'm creating a dynamic web project in Eclipse (almost from scratch) and I created a JSPX file where I put
<head>...
<script type="text/javascript" src="route/to/scripts/jquery.js"></script>
<script type="text/javascript" src="route/to/scripts/jquery.ui.js"></script>
<script type="text/javascript" src="route/to/scripts/something.js"></script>
</head>
我打算使用 Jquery UI可排序我发现使用JSPX,只有第一个脚本在Firefox和IE中加载(而在Opera中它可以工作......)。如果我使用纯JSP,无论是否是XHTML的HTML,它都会加载所有JS文件。
I intend to use Jquery UI sortable and I found out that using JSPX, only the first script loads in Firefox and IE (while in opera it works...). If I use plain JSP, whether HTML of XHTML, it loads all the JS files.
有没有办法在不使用
<script>
<jsp:include ...>
</script>
我必须知道吗? (因为这个加载脚本INTO到最后的(X)HTML)
that I must be aware of? (because this one loads the script INTO the final (X)HTML)
编辑:只是想...为什么Opera在FF和IE失败时读取xhtml权限阅读< script>
标签?这可能是一个错误吗?
Just thinking... why does Opera read the xhtml right while FF and IE failed at reading the <script>
tags? Could it be a bug?
推荐答案
JSPX有一种古怪的行为,它自动折叠没有正文的标签。所以有效
JSPX has the quirky behaviour that it auto-collapses tags without body. So effectively
<script type="text/javascript" src="route/to/scripts/jquery.js"></script>
<script type="text/javascript" src="route/to/scripts/jquery.ui.js"></script>
<script type="text/javascript" src="route/to/scripts/something.js"></script>
将以浏览器结尾
<script type="text/javascript" src="route/to/scripts/jquery.js" />
<script type="text/javascript" src="route/to/scripts/jquery.ui.js" />
<script type="text/javascript" src="route/to/scripts/something.js" />
无效< script>
语法(在浏览器中右键单击页面并执行查看源以自行查看)。浏览器行为未确定。
which is invalid <script>
syntax (rightclick page in browser and do View Source to see it yourself). The browser behaviour is undetermined.
您可以通过在< jsp:text />
之间添加标签
You can workaround this by putting a <jsp:text />
between the tags
<script type="text/javascript" src="route/to/scripts/jquery.js"><jsp:text /></script>
<script type="text/javascript" src="route/to/scripts/jquery.ui.js"><jsp:text /></script>
<script type="text/javascript" src="route/to/scripts/something.js"><jsp:text /></script>
这篇关于在JSPX文件中包含JS文件(JQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!