这是我的XHTML页面的代码.jQuery /js/
位于我的应用程序的文件夹中.所有其他页面的验证都是使用相同的文件使用jQuery完成的,但我无法在我创建的这个测试页面上运行简单的jQuery代码.这是页面的代码:
<?xml version='1.0' encoding='UTF-8' ?>
<!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"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<script type="text/javascript" src="js/jquery.js"></script>
<script>
$(document).ready(function () {
$("p").text("The DOM is now loaded and can be manipulated.");
});
</script>
<br/><br/><br/>
<p>Not loaded yet.</p>
<input id="pedram" type="text" onclick="alert('hi');"/>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
我也试过用CDATA
标签.我还将脚本移到了文档的头部.
唯一正确运作的是alert()
我把它放在onclick
事件中.没有别的办法.
请告诉我我做错了什么.
更改
<script src="js/jquery.js">
$(document).ready(function () {
$("p").text("The DOM is now loaded and can be manipulated.");
});
</script>
Run Code Online (Sandbox Code Playgroud)
至
<script>
$(document).ready(function () {
$("p").text("The DOM is now loaded and can be manipulated.");
});
</script>
Run Code Online (Sandbox Code Playgroud)
您不需要两次指定jQuery源..当您在标记内使用js时也不需要