[英]jQuery's ready() function works in .jsp, but not in .jspx
這個jsp的工作原理:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"> </script>
<script type="text/javascript" src="jqReady.js"> </script>
</head>
<body>
<div id="hello">Empty</div>
</body>
</html>
此jspx不起作用:
<?xml version="1.0" encoding="utf-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"><!-- required for FF3 and Opera --><jsp:text> </jsp:text></script>
<script type="text/javascript" src="jqReady.js"><!-- required for FF3 and Opera --><jsp:text> </jsp:text></script>
</head>
<body>
<div id="hello">Empty</div>
</body>
</html>
</jsp:root>
兩者都使用相同的jqReady.js
:
$(document).ready(function() {
$("#hello").text("Hello, world " + new Date());
$("body").css("background-color", "grey");
});
如果是jspx ,則不會調用傳遞給ready()
的函數。
使用Firebug,我觀察到$.isReady
我正在使用Iceweasel 3.5.16(例如Firefox 3.5.15),JBoss 7.1.1
相關問題/答案(我已經應用了這些建議):
我在這里找到了解決方案: HTML5 JSPX模板
使用該頁面上的模板,此JSPX可以按預期工作:
<?xml version="1.0" encoding="utf-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page contentType="text/html" pageEncoding="utf-8" />
<jsp:output omit-xml-declaration="true" />
<jsp:output doctype-root-element="HTML"
doctype-system="about:legacy-compat" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"><!-- required for FF3 and Opera --><jsp:text> </jsp:text></script>
<script type="text/javascript" src="jqReady.js"><!-- required for FF3 and Opera --><jsp:text> </jsp:text></script>
</head>
<body>
<div id="hello">Empty</div>
</body>
</html>
</jsp:root>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.