【问题标题】:jQuery Error after JSPX Parsing in Spring Application在 Spring 应用程序中解析 JSPX 后出现 jQuery 错误
【发布时间】:2012-06-06 09:11:04
【问题描述】:

我有一个非常奇怪的问题: 我在我的应用程序中使用 Spring Framework 3.0.5。为了呈现视图,我使用 Tiles 框架。

这是布局jspx文件的来源:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:tiles="http://tiles.apache.org/tags-tiles" xmlns:spring="http://www.springframework.org/tags" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" >  
<jsp:output doctype-root-element="html" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>          
<jsp:output omit-xml-declaration="yes"/>

<head>

</head>

<body>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/jquery.js"></script>
    <img id="testimg" src="${pageContext.request.contextPath}/resources/images/logo.png" onclick="$(this).fadeOut()" />
</body>

现在的问题是:每次我加载页面时,我都会从 jQuery 调用中得到一个 JavaScript 错误,并且没有执行进一步的 js 代码:

    Error: c.removeAttribute is not a function

但是如果我将页面的源代码复制并粘贴到本地文件中并用浏览器打开它,一切都很好(不同的是,tomcat 不交付页面)。

渲染的页面如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head />
<body>
    <script src="/myContext/resources/js/jquery.js"
    type="text/javascript">

    </script>
    <img onclick="$(this).fadeOut()"
    src="/myContext/resources/images/logo.png" id="testimg" />
</body>
</html>

图片显示正确,同时也加载了query.js。 我真的没有想法了。希望有人能帮帮我!!

提前致谢!

更新: 此效果仅在 Safari 和 FF 中出现。在谷歌浏览器上它可以工作!! 而且我忘了提,我正在使用 Mac...

【问题讨论】:

    标签: jquery spring jsp


    【解决方案1】:

    您提到您正在使用 JSPX。我建议你尝试在&lt;script&gt;&lt;/script&gt;之间添加注释,即

    <script ...> <!-- please keep me --> </script>
    

    否则JSPX编译器会将&lt;script&gt;标签变成&lt;script .../&gt;,浏览器渲染时会出错。 (这是我的猜测,我认为应该是对的。)

    我不知道具体原因,但是我遇到了和你一样的问题,我用那个方法解决了。如果您能找出详细原因,请告诉我。

    谢谢!

    【讨论】:

      猜你喜欢
      • 2020-01-15
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多